Exemple #1
0
        /// <summary>
        /// Run the network using the run technique implemented by this trainer.
        /// </summary>
        /// <param name="mycaffe">Specifies an instance to the MyCaffeControl component.</param>
        /// <param name="nN">Specifies the number of samples to run.</param>
        /// <param name="type">Specifies the output data type returned as a raw byte stream.</param>
        /// <returns>The run results are returned in the same native type as that of the CustomQuery used.</returns>
        public byte[] Run(Component mycaffe, int nN, out string type)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, Stage.RL);
            }

            string strRunProperties = null;
            IXMyCaffeCustomTrainerCallbackRNN icallback = m_icallback as IXMyCaffeCustomTrainerCallbackRNN;

            if (icallback != null)
            {
                strRunProperties = icallback.GetRunProperties();
            }

            IxTrainerRL itrainer = m_itrainer as IxTrainerRL;

            if (itrainer == null)
            {
                throw new Exception("The IxTrainerRL interface must be implemented.");
            }

            byte[] rgResults = itrainer.Run(nN, strRunProperties, out type);
            m_itrainer.Shutdown(0);
            m_itrainer = null;

            return(rgResults);
        }
Exemple #2
0
        /// <summary>
        /// Run the network using the run technique implemented by this trainer.
        /// </summary>
        /// <param name="mycaffe">Specifies an instance to the MyCaffeControl component.</param>
        /// <param name="nN">Specifies the number of samples to run.</param>
        /// <param name="type">Specifies the output data type returned as a raw byte stream.</param>
        /// <returns>The run results are returned in the same native type as that of the CustomQuery used.</returns>
        byte[] IXMyCaffeCustomTrainerRNN.Run(Component mycaffe, int nN, out string type)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, Stage.RNN);
            }

            IxTrainerRNN itrainer = m_itrainer as IxTrainerRNN;

            if (itrainer == null)
            {
                throw new Exception("The trainer must be set to to 'RNN.SIMPLE' to run in recurrent learning mode.");
            }

            string strRunProperties = null;
            IXMyCaffeCustomTrainerCallbackRNN icallback = m_icallback as IXMyCaffeCustomTrainerCallbackRNN;

            if (icallback != null)
            {
                strRunProperties = icallback.GetRunProperties();
            }

            byte[] rgResults = itrainer.Run(nN, strRunProperties, out type);
            m_itrainer.Shutdown(0);
            m_itrainer = null;

            return(rgResults);
        }
        /// <summary>
        /// Create a new trainer and use it to run a single run cycle.
        /// </summary>
        /// <param name="mycaffe">Specifies the MyCaffeControl to use.</param>
        /// <param name="nN">Specifies the number of samples to run.</param>
        /// <returns>The results of the run are returned.</returns>
        float[] IXMyCaffeCustomTrainerRNN.Run(Component mycaffe, int nN)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, Stage.RNN);
            }

            IxTrainerRNN itrainer = m_itrainer as IxTrainerRNN;

            if (itrainer == null)
            {
                throw new Exception("The trainer must be set to to 'RNN.SIMPLE' to run in recurrent learning mode.");
            }

            PropertySet runProp = null;
            IXMyCaffeCustomTrainerCallbackRNN icallback = m_icallback as IXMyCaffeCustomTrainerCallbackRNN;

            if (icallback != null)
            {
                runProp = icallback.GetRunProperties();
            }

            float[] rgResults = itrainer.Run(nN, runProp);
            cleanup(0, false);

            return(rgResults);
        }
Exemple #4
0
        /// <summary>
        /// Releases any resources used by the component.
        /// </summary>
        public void CleanUp()
        {
            if (m_itrainer != null)
            {
                m_itrainer.Shutdown(3000);
                m_itrainer = null;
            }

            shutdown();
        }
        /// <summary>
        /// Create a new trainer and use it to run a training cycle using the current 'stage' = RNN or RL.
        /// </summary>
        /// <param name="mycaffe">Specifies the MyCaffeControl to use.</param>
        /// <param name="nIterationOverride">Specifies the iterations to run if greater than zero.</param>
        /// <param name="type">Specifies the type of iterator to use.</param>
        /// <param name="step">Optionally, specifies whether or not to step the training for debugging (default = NONE).</param>
        public void Train(Component mycaffe, int nIterationOverride, ITERATOR_TYPE type = ITERATOR_TYPE.ITERATION, TRAIN_STEP step = TRAIN_STEP.NONE)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, getStage());
            }

            if (nIterationOverride == -1)
            {
                nIterationOverride = m_nIterations;
            }

            m_itrainer.Train(nIterationOverride, type, step);
            cleanup(1000, false);
        }
        /// <summary>
        /// Create a new trainer and use it to run a test cycle using the current 'stage' = RNN or RL.
        /// </summary>
        /// <param name="mycaffe">Specifies the MyCaffeControl to use.</param>
        /// <param name="nIterationOverride">Specifies the iterations to run if greater than zero.</param>
        /// <param name="type">Specifies the type of iterator to use.</param>
        public void Test(Component mycaffe, int nIterationOverride, ITERATOR_TYPE type = ITERATOR_TYPE.ITERATION)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, getStage());
            }

            if (nIterationOverride == -1)
            {
                nIterationOverride = m_nIterations;
            }

            m_itrainer.Test(nIterationOverride, type);
            cleanup(500, false);
        }
        private void cleanup(int nWait, bool bCallShutdown)
        {
            lock (m_syncObj)
            {
                if (m_itrainer != null)
                {
                    m_itrainer.Shutdown(nWait);
                    m_itrainer = null;
                }

                if (bCallShutdown)
                {
                    shutdown();
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Create a new trainer and use it to run a training cycle using the current 'stage' = RNN or RL.
        /// </summary>
        /// <param name="mycaffe">Specifies the MyCaffeControl to use.</param>
        /// <param name="nIterationOverride">Specifies the iterations to run if greater than zero.</param>
        /// <param name="step">Optionally, specifies whether or not to step the training for debugging (default = NONE).</param>
        public void Train(Component mycaffe, int nIterationOverride, TRAIN_STEP step = TRAIN_STEP.NONE)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, getStage());
            }

            if (nIterationOverride == -1)
            {
                nIterationOverride = m_nIterations;
            }

            m_itrainer.Train(nIterationOverride, step);
            m_itrainer.Shutdown(1000);
            m_itrainer = null;
        }
Exemple #9
0
        /// <summary>
        /// Create a new trainer and use it to run a test cycle using the current 'stage' = RNN or RL.
        /// </summary>
        /// <param name="mycaffe">Specifies the MyCaffeControl to use.</param>
        /// <param name="nIterationOverride">Specifies the iterations to run if greater than zero.</param>
        public void Test(Component mycaffe, int nIterationOverride)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, getStage());
            }

            if (nIterationOverride == -1)
            {
                nIterationOverride = m_nIterations;
            }

            m_itrainer.Test(nIterationOverride);
            m_itrainer.Shutdown(500);
            m_itrainer = null;
        }
Exemple #10
0
        private IxTrainer createTrainer(Component mycaffe, Stage stage)
        {
            IxTrainer itrainer = null;

            if (mycaffe is MyCaffeControl <double> )
            {
                itrainer = create_trainerD(mycaffe, stage);
            }
            else
            {
                itrainer = create_trainerF(mycaffe, stage);
            }

            itrainer.Initialize();

            return(itrainer);
        }
        /// <summary>
        /// Create a new trainer and use it to run a single run cycle.
        /// </summary>
        /// <param name="mycaffe">Specifies the MyCaffeControl to use.</param>
        /// <param name="nDelay">Specifies a delay to wait before getting the action.</param>
        /// <returns>The results of the run are returned.</returns>
        ResultCollection IXMyCaffeCustomTrainerRL.RunOne(Component mycaffe, int nDelay)
        {
            if (m_itrainer == null)
            {
                m_itrainer = createTrainer(mycaffe, Stage.RL);
            }

            IxTrainerRL itrainer = m_itrainer as IxTrainerRL;

            if (itrainer == null)
            {
                throw new Exception("The trainer must be set to to 'C51.ST', PG.SIMPLE', 'PG.ST' or 'PG.MT' to run in reinforcement learning mode.");
            }

            ResultCollection res = itrainer.RunOne(nDelay);

            cleanup(50, false);

            return(res);
        }