internal static RemotePolicyInitializedEvent GetEventForRemotePolicy( string behaviorName, IList <ISensor> sensors, ActionSpec actionSpec, IList <IActuator> actuators ) { var remotePolicyEvent = new RemotePolicyInitializedEvent(); // Hash the behavior name so that there's no concern about PII or "secret" data being leaked. remotePolicyEvent.BehaviorName = AnalyticsUtils.Hash(behaviorName); remotePolicyEvent.TrainingSessionGuid = s_TrainingSessionGuid.ToString(); remotePolicyEvent.ActionSpec = EventActionSpec.FromActionSpec(actionSpec); remotePolicyEvent.ObservationSpecs = new List <EventObservationSpec>(sensors.Count); foreach (var sensor in sensors) { remotePolicyEvent.ObservationSpecs.Add(EventObservationSpec.FromSensor(sensor)); } remotePolicyEvent.ActuatorInfos = new List <EventActuatorInfo>(actuators.Count); foreach (var actuator in actuators) { remotePolicyEvent.ActuatorInfos.Add(EventActuatorInfo.FromActuator(actuator)); } remotePolicyEvent.MLAgentsEnvsVersion = s_TrainerPackageVersion; remotePolicyEvent.TrainerCommunicationVersion = s_TrainerCommunicationVersion; return(remotePolicyEvent); }
/// <summary> /// Generate an InferenceEvent for the model. /// </summary> /// <param name="nnModel"></param> /// <param name="behaviorName"></param> /// <param name="inferenceDevice"></param> /// <param name="sensors"></param> /// <param name="actionSpec"></param> /// <param name="actuators"></param> /// <returns></returns> internal static InferenceEvent GetEventForModel( NNModel nnModel, string behaviorName, InferenceDevice inferenceDevice, IList <ISensor> sensors, ActionSpec actionSpec, IList <IActuator> actuators ) { var barracudaModel = ModelLoader.Load(nnModel); var inferenceEvent = new InferenceEvent(); // Hash the behavior name so that there's no concern about PII or "secret" data being leaked. inferenceEvent.BehaviorName = AnalyticsUtils.Hash(behaviorName); inferenceEvent.BarracudaModelSource = barracudaModel.IrSource; inferenceEvent.BarracudaModelVersion = barracudaModel.IrVersion; inferenceEvent.BarracudaModelProducer = barracudaModel.ProducerName; inferenceEvent.MemorySize = (int)barracudaModel.GetTensorByName(TensorNames.MemorySize)[0]; inferenceEvent.InferenceDevice = (int)inferenceDevice; if (barracudaModel.ProducerName == "Script") { // .nn files don't have these fields set correctly. Assign some placeholder values. inferenceEvent.BarracudaModelSource = "NN"; inferenceEvent.BarracudaModelProducer = "tensorflow_to_barracuda.py"; } #if UNITY_EDITOR var barracudaPackageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(Tensor).Assembly); inferenceEvent.BarracudaPackageVersion = barracudaPackageInfo.version; #else inferenceEvent.BarracudaPackageVersion = null; #endif inferenceEvent.ActionSpec = EventActionSpec.FromActionSpec(actionSpec); inferenceEvent.ObservationSpecs = new List <EventObservationSpec>(sensors.Count); foreach (var sensor in sensors) { inferenceEvent.ObservationSpecs.Add(EventObservationSpec.FromSensor(sensor)); } inferenceEvent.ActuatorInfos = new List <EventActuatorInfo>(actuators.Count); foreach (var actuator in actuators) { inferenceEvent.ActuatorInfos.Add(EventActuatorInfo.FromActuator(actuator)); } inferenceEvent.TotalWeightSizeBytes = GetModelWeightSize(barracudaModel); inferenceEvent.ModelHash = GetModelHash(barracudaModel); return(inferenceEvent); }