public void OnDisable() { #if !ENABLE_TENSORFLOW _engine?.Dispose(); #endif _tensorAllocator?.Reset(false); }
/// <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 OnDisable() { _engine?.Dispose(); }