public void Construction() { var alloc = new TensorCachingAllocator(); var mem = new Dictionary <int, List <float> >(); var tensorGenerator = new TensorGenerator(0, alloc, mem); Assert.IsNotNull(tensorGenerator); alloc.Dispose(); }
/// <summary> /// Initializes the Brain with the Model that it will use when selecting actions for /// the agents /// </summary> /// <param name="seed"> The seed that will be used to initialize the RandomNormal /// and Multinomial obsjects used when running inference.</param> /// <exception cref="UnityAgentsException">Throws an error when the model is null /// </exception> public void ReloadModel(int seed = 0) { if (_tensorAllocator == null) { _tensorAllocator = new TensorCachingAllocator(); } #if ENABLE_TENSORFLOW if (model != null) { _engine = new TFSharpInferenceEngine(); _engine.PrepareModel(model.bytes); } else { _engine = null; } _modelParamLoader = ModelParamLoader.GetLoaderAndCheck(_engine, brainParameters); _inferenceInputs = _modelParamLoader.GetInputTensors(); _inferenceOutputs = _modelParamLoader.GetOutputTensors(); _tensorGenerator = new TensorGenerator(brainParameters, seed, _tensorAllocator); _tensorApplier = new TensorApplier(brainParameters, seed, _tensorAllocator); #else if (model != null) { #if BARRACUDA_VERBOSE _verbose = true; #endif D.logEnabled = _verbose; // Cleanup previous instance if (_engine != null) { _engine.Dispose(); } _barracudaModel = ModelLoader.Load(model.Value); var executionDevice = inferenceDevice == InferenceDevice.GPU ? BarracudaWorkerFactory.Type.ComputePrecompiled : BarracudaWorkerFactory.Type.CSharp; _engine = BarracudaWorkerFactory.CreateWorker(executionDevice, _barracudaModel, _verbose); } else { _barracudaModel = null; _engine = null; } _modelParamLoader = BarracudaModelParamLoader.GetLoaderAndCheck(_engine, _barracudaModel, brainParameters); _inferenceInputs = _modelParamLoader.GetInputTensors(); _outputNames = _modelParamLoader.GetOutputNames(); _tensorGenerator = new TensorGenerator(brainParameters, seed, _tensorAllocator, _barracudaModel); _tensorApplier = new TensorApplier(brainParameters, seed, _tensorAllocator, _barracudaModel); #endif }
public void Contruction() { var bp = new BrainParameters(); var alloc = new TensorCachingAllocator(); var tensorGenerator = new TensorGenerator(bp, 0, alloc); Assert.IsNotNull(tensorGenerator); alloc.Dispose(); }
/// <summary> /// Initializes the Brain with the Model that it will use when selecting actions for /// the agents /// </summary> /// <param name="seed"> The seed that will be used to initialize the RandomNormal /// and Multinomial obsjects used when running inference.</param> /// <exception cref="UnityAgentsException">Throws an error when the model is null /// </exception> public void ReloadModel(int seed = 0) { #if ENABLE_TENSORFLOW if (model != null) { _engine = new TFSharpInferenceEngine(); _engine.PrepareModel(model.bytes); } else { _engine = null; } _modelParamLoader = ModelParamLoader.GetLoaderAndCheck(_engine, brainParameters); _inferenceInputs = _modelParamLoader.GetInputTensors(); _inferenceOutputs = _modelParamLoader.GetOutputTensors(); _tensorGenerator = new TensorGenerator(brainParameters, seed); _tensorApplier = new TensorApplier(brainParameters, seed); #endif }
/// <summary> /// Initializes the Brain with the Model that it will use when selecting actions for /// the agents /// </summary> /// <param name="seed"> The seed that will be used to initialize the RandomNormal /// and Multinomial obsjects used when running inference.</param> /// <exception cref="UnityAgentsException">Throws an error when the model is null /// </exception> public void ReloadModel(int seed = 0) { if (m_TensorAllocator == null) { m_TensorAllocator = new TensorCachingAllocator(); } if (model != null) { #if BARRACUDA_VERBOSE _verbose = true; #endif D.logEnabled = m_Verbose; // Cleanup previous instance if (m_Engine != null) { m_Engine.Dispose(); } m_BarracudaModel = ModelLoader.Load(model.Value); var executionDevice = inferenceDevice == InferenceDevice.GPU ? BarracudaWorkerFactory.Type.ComputePrecompiled : BarracudaWorkerFactory.Type.CSharp; m_Engine = BarracudaWorkerFactory.CreateWorker(executionDevice, m_BarracudaModel, m_Verbose); } else { m_BarracudaModel = null; m_Engine = null; } m_ModelParamLoader = BarracudaModelParamLoader.GetLoaderAndCheck(m_Engine, m_BarracudaModel, brainParameters); m_InferenceInputs = m_ModelParamLoader.GetInputTensors(); m_OutputNames = m_ModelParamLoader.GetOutputNames(); m_TensorGenerator = new TensorGenerator(brainParameters, seed, m_TensorAllocator, m_BarracudaModel); m_TensorApplier = new TensorApplier(brainParameters, seed, m_TensorAllocator, m_BarracudaModel); }