/// <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); }
/// <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 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> public ResultCollection RunOne(Component mycaffe, int nDelay = 1000) { if (m_itrainer == null) { m_itrainer = createTrainer(mycaffe); } ResultCollection res = m_itrainer.RunOne(nDelay); cleanup(50); return(res); }
/// <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> public ResultCollection Run(Component mycaffe, int nDelay = 1000) { if (m_itrainer == null) { m_itrainer = createTrainer(mycaffe); } ResultCollection res = m_itrainer.Run(nDelay); m_itrainer.Shutdown(50); m_itrainer = null; return(res); }
/// <summary> /// Create a new trainer and use it to run a training cycle. /// </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); } if (nIterationOverride == -1) { nIterationOverride = m_nItertions; } m_itrainer.Train(nIterationOverride, type, step); cleanup(1000); }
/// <summary> /// Create a new trainer and use it to run a test cycle. /// </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); } if (nIterationOverride == -1) { nIterationOverride = m_nItertions; } m_itrainer.Test(nIterationOverride, type); cleanup(500); }
/// <summary> /// Create a new trainer and use it to run a training cycle. /// </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); } if (nIterationOverride == -1) { nIterationOverride = m_nItertions; } m_itrainer.Train(nIterationOverride, step); m_itrainer.Shutdown(1000); m_itrainer = null; }
/// <summary> /// Create a new trainer and use it to run a test cycle. /// </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); } if (nIterationOverride == -1) { nIterationOverride = m_nItertions; } m_itrainer.Test(nIterationOverride); m_itrainer.Shutdown(500); m_itrainer = null; }
private void cleanup(int nWait, bool bCallShutdown = false) { lock (m_syncObj) { if (m_itrainer != null) { m_itrainer.Shutdown(nWait); m_itrainer = null; } if (bCallShutdown) { shutdown(); } } }
private IxTrainerRL createTrainer(Component mycaffe) { IxTrainerRL itrainer = null; if (mycaffe is MyCaffeControl <double> ) { itrainer = create_trainerD(mycaffe); } else { itrainer = create_trainerF(mycaffe); } itrainer.Initialize(); return(itrainer); }
/// <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); } string strRunProperties = null; IXMyCaffeCustomTrainerCallbackRNN icallback = m_icallback as IXMyCaffeCustomTrainerCallbackRNN; if (icallback != null) { strRunProperties = icallback.GetRunProperties(); } byte[] rgResults = m_itrainer.Run(nN, strRunProperties, out type); cleanup(0); 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="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); }