/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (m_Brain == null) { return; } m_Info.storedVectorActions = m_Action.vectorActions; m_ActionMasker.ResetMask(); UpdateSensors(); using (TimerStack.Instance.Scoped("CollectObservations")) { CollectObservations(collectObservationsSensor, m_ActionMasker); } m_Info.actionMasks = m_ActionMasker.GetMask(); m_Info.reward = m_Reward; m_Info.done = false; m_Info.maxStepReached = false; m_Info.episodeId = m_EpisodeId; m_Brain.RequestDecision(m_Info, sensors); // If we have any DemonstrationWriters, write the AgentInfo and sensors to them. foreach (var demoWriter in DemonstrationWriters) { demoWriter.Record(m_Info, sensors); } }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (m_Brain == null) { return; } m_Info.storedVectorActions = m_Action.vectorActions; m_ActionMasker.ResetMask(); UpdateSensors(); using (TimerStack.Instance.Scoped("CollectObservations")) { CollectObservations(); } m_Info.actionMasks = m_ActionMasker.GetMask(); m_Info.reward = m_Reward; m_Info.done = m_Done; m_Info.maxStepReached = m_MaxStepReached; m_Info.id = m_Id; m_Brain.RequestDecision(m_Info, sensors, UpdateAgentAction); if (m_Recorder != null && m_Recorder.record && Application.isEditor) { m_Recorder.WriteExperience(m_Info, sensors); } }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (m_Brain == null) { return; } m_Info.memories = m_Action.memories; m_Info.storedVectorActions = m_Action.vectorActions; m_Info.storedTextActions = m_Action.textActions; m_Info.vectorObservation.Clear(); m_Info.compressedObservations.Clear(); m_ActionMasker.ResetMask(); using (TimerStack.Instance.Scoped("CollectObservations")) { CollectObservations(); } m_Info.actionMasks = m_ActionMasker.GetMask(); var param = m_PolicyFactory.brainParameters; if (m_Info.vectorObservation.Count != param.vectorObservationSize) { throw new UnityAgentsException(string.Format( "Vector Observation size mismatch in continuous " + "agent {0}. " + "Was Expecting {1} but received {2}. ", gameObject.name, param.vectorObservationSize, m_Info.vectorObservation.Count)); } Utilities.ShiftLeft(m_Info.stackedVectorObservation, param.vectorObservationSize); Utilities.ReplaceRange(m_Info.stackedVectorObservation, m_Info.vectorObservation, m_Info.stackedVectorObservation.Count - m_Info.vectorObservation.Count); m_Info.reward = m_Reward; m_Info.done = m_Done; m_Info.maxStepReached = m_MaxStepReached; m_Info.id = m_Id; m_Brain.RequestDecision(this); if (m_Recorder != null && m_Recorder.record && Application.isEditor) { // This is a bit of a hack - if we're in inference mode, compressed observations won't be generated // But we need these to be generated for the recorder. So generate them here. if (m_Info.compressedObservations.Count == 0) { GenerateSensorData(); } m_Recorder.WriteExperience(m_Info); } m_Info.textObservation = ""; }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (m_Brain == null) { return; } m_Info.storedVectorActions = m_Action.vectorActions; m_ActionMasker.ResetMask(); UpdateSensors(); using (TimerStack.Instance.Scoped("CollectObservations")) { CollectObservations(); } m_Info.actionMasks = m_ActionMasker.GetMask(); // var param = m_PolicyFactory.brainParameters; // look, no brain params! m_Info.reward = m_Reward; m_Info.done = m_Done; m_Info.maxStepReached = m_MaxStepReached; m_Info.id = m_Id; m_Brain.RequestDecision(m_Info, sensors, UpdateAgentAction); if (m_Recorder != null && m_Recorder.record && Application.isEditor) { if (m_VectorSensorBuffer == null) { // Create a buffer for writing uncompressed (i.e. float) sensor data to m_VectorSensorBuffer = new float[sensors.GetSensorFloatObservationSize()]; } // This is a bit of a hack - if we're in inference mode, observations won't be generated // But we need these to be generated for the recorder. So generate them here. var observations = new List <Observation>(); GenerateSensorData(sensors, m_VectorSensorBuffer, m_WriteAdapter, observations); m_Recorder.WriteExperience(m_Info, observations); } }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (m_Brain == null) { return; } m_Info.storedVectorActions = m_Action.vectorActions; m_Info.observations.Clear(); m_ActionMasker.ResetMask(); UpdateSensors(); using (TimerStack.Instance.Scoped("CollectObservations")) { CollectObservations(); } m_Info.actionMasks = m_ActionMasker.GetMask(); // var param = m_PolicyFactory.brainParameters; // look, no brain params! m_Info.reward = m_Reward; m_Info.done = m_Done; m_Info.maxStepReached = m_MaxStepReached; m_Info.id = m_Id; m_Brain.RequestDecision(this); if (m_Recorder != null && m_Recorder.record && Application.isEditor) { // This is a bit of a hack - if we're in inference mode, observations won't be generated // But we need these to be generated for the recorder. So generate them here. if (m_Info.observations.Count == 0) { GenerateSensorData(); } m_Recorder.WriteExperience(m_Info); } }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (brain == null) { return; } info.memories = action.memories; info.storedVectorActions = action.vectorActions; info.storedTextActions = action.textActions; info.vectorObservation.Clear(); actionMasker.ResetMask(); CollectObservations(); info.actionMasks = actionMasker.GetMask(); BrainParameters param = brain.brainParameters; if (info.vectorObservation.Count != param.vectorObservationSize) { throw new UnityAgentsException(string.Format( "Vector Observation size mismatch between continuous " + "agent {0} and brain {1}. " + "Was Expecting {2} but received {3}. ", gameObject.name, brain.name, brain.brainParameters.vectorObservationSize, info.vectorObservation.Count)); } info.stackedVectorObservation.RemoveRange( 0, param.vectorObservationSize); info.stackedVectorObservation.AddRange(info.vectorObservation); info.visualObservations.Clear(); var visualObservationCount = agentParameters.agentCameras.Count + agentParameters.agentRenderTextures.Count; if (param.cameraResolutions.Length > visualObservationCount) { throw new UnityAgentsException(string.Format( "Not enough cameras/renderTextures for agent {0} : Brain {1} expecting at " + "least {2} cameras/renderTextures but only {3} were present.", gameObject.name, brain.name, brain.brainParameters.cameraResolutions.Length, visualObservationCount)); } //First add all cameras for (int i = 0; i < agentParameters.agentCameras.Count; i++) { ObservationToTexture( agentParameters.agentCameras[i], param.cameraResolutions[i].width, param.cameraResolutions[i].height, ref textureArray[i]); info.visualObservations.Add(textureArray[i]); } //Then add all renderTextures var camCount = agentParameters.agentCameras.Count; for (int i = 0; i < agentParameters.agentRenderTextures.Count; i++) { ObservationToTexture( agentParameters.agentRenderTextures[i], param.cameraResolutions[camCount + i].width, param.cameraResolutions[camCount + i].height, ref textureArray[i]); info.visualObservations.Add(textureArray[i]); } info.reward = reward; info.done = done; info.maxStepReached = maxStepReached; info.id = id; brain.SendState(this, info); if (recorder != null && recorder.record && Application.isEditor) { recorder.WriteExperience(info); } info.textObservation = ""; }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (brain == null) { return; } info.memories = action.memories; info.storedVectorActions = action.vectorActions; info.storedTextActions = action.textActions; info.vectorObservation.Clear(); actionMasker.ResetMask(); CollectObservations(); info.actionMasks = actionMasker.GetMask(); BrainParameters param = brain.brainParameters; if (info.vectorObservation.Count != param.vectorObservationSize) { throw new UnityAgentsException(string.Format( "Vector Observation size mismatch between continuous " + "agent {0} and brain {1}. " + "Was Expecting {2} but received {3}. ", gameObject.name, brain.gameObject.name, brain.brainParameters.vectorObservationSize, info.vectorObservation.Count)); } info.stackedVectorObservation.RemoveRange( 0, param.vectorObservationSize); info.stackedVectorObservation.AddRange(info.vectorObservation); info.visualObservations.Clear(); // M.Baske: Optional custom texture, replacing cam if set. if (customTexture != null) { info.visualObservations.Add(customTexture); } else { if (param.cameraResolutions.Length > agentParameters.agentCameras.Count) { throw new UnityAgentsException(string.Format( "Not enough cameras for agent {0} : Bain {1} expecting at " + "least {2} cameras but only {3} were present.", gameObject.name, brain.gameObject.name, brain.brainParameters.cameraResolutions.Length, agentParameters.agentCameras.Count)); } for (int i = 0; i < brain.brainParameters.cameraResolutions.Length; i++) { ObservationToTexture( agentParameters.agentCameras[i], param.cameraResolutions[i].width, param.cameraResolutions[i].height, ref textureArray[i]); info.visualObservations.Add(textureArray[i]); } } info.reward = reward; info.done = done; info.maxStepReached = maxStepReached; info.id = id; brain.SendState(this, info); info.textObservation = ""; }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (brain == null) { return; } info.memories = action.memories; info.storedVectorActions = action.vectorActions; info.storedTextActions = action.textActions; info.vectorObservation.Clear(); actionMasker.ResetMask(); CollectObservations(); info.actionMasks = actionMasker.GetMask(); BrainParameters param = brain.brainParameters; if (info.vectorObservation.Count != param.vectorObservationSize) { throw new UnityAgentsException(string.Format( "Vector Observation size mismatch between continuous " + "agent {0} and brain {1}. " + "Was Expecting {2} but received {3}. ", gameObject.name, brain.gameObject.name, brain.brainParameters.vectorObservationSize, info.vectorObservation.Count)); } info.stackedVectorObservation.RemoveRange( 0, param.vectorObservationSize); info.stackedVectorObservation.AddRange(info.vectorObservation); info.visualObservations.Clear(); /// Modified by M.Baske to enable frame-stacking. /// if (visualObservations) { visualObservations.ApplyObservations(this, info.visualObservations); } /// Original code: /* * if (param.cameraResolutions.Length > agentParameters.agentCameras.Count) * { * throw new UnityAgentsException(string.Format( * "Not enough cameras for agent {0} : Bain {1} expecting at " + * "least {2} cameras but only {3} were present.", * gameObject.name, brain.gameObject.name, * brain.brainParameters.cameraResolutions.Length, * agentParameters.agentCameras.Count)); * } * * for (int i = 0; i < brain.brainParameters.cameraResolutions.Length; i++) * { * ObservationToTexture( * agentParameters.agentCameras[i], * param.cameraResolutions[i].width, * param.cameraResolutions[i].height, * ref textureArray[i]); * info.visualObservations.Add(textureArray[i]); * } */ info.reward = reward; info.done = done; info.maxStepReached = maxStepReached; info.id = id; brain.SendState(this, info); info.textObservation = ""; }
/// <summary> /// Sends the Agent info to the linked Brain. /// </summary> void SendInfoToBrain() { if (brain == null) { return; } m_Info.memories = m_Action.memories; m_Info.storedVectorActions = m_Action.vectorActions; m_Info.storedTextActions = m_Action.textActions; m_Info.vectorObservation.Clear(); m_ActionMasker.ResetMask(); CollectObservations(); m_Info.actionMasks = m_ActionMasker.GetMask(); var param = brain.brainParameters; if (m_Info.vectorObservation.Count != param.vectorObservationSize) { throw new UnityAgentsException(string.Format( "Vector Observation size mismatch between continuous " + "agent {0} and brain {1}. " + "Was Expecting {2} but received {3}. ", gameObject.name, brain.name, brain.brainParameters.vectorObservationSize, m_Info.vectorObservation.Count)); } Utilities.ShiftLeft(m_Info.stackedVectorObservation, param.vectorObservationSize); Utilities.ReplaceRange(m_Info.stackedVectorObservation, m_Info.vectorObservation, m_Info.stackedVectorObservation.Count - m_Info.vectorObservation.Count); m_Info.visualObservations.Clear(); var visualObservationCount = agentParameters.agentCameras.Count + agentParameters.agentRenderTextures.Count; if (param.cameraResolutions.Length > visualObservationCount) { throw new UnityAgentsException(string.Format( "Not enough cameras/renderTextures for agent {0} : Brain {1} expecting at " + "least {2} cameras/renderTextures but only {3} were present.", gameObject.name, brain.name, brain.brainParameters.cameraResolutions.Length, visualObservationCount)); } //First add all cameras for (var i = 0; i < agentParameters.agentCameras.Count; i++) { var obsTexture = ObservationToTexture( agentParameters.agentCameras[i], param.cameraResolutions[i].width, param.cameraResolutions[i].height); m_Info.visualObservations.Add(obsTexture); } //Then add all renderTextures var camCount = agentParameters.agentCameras.Count; for (var i = 0; i < agentParameters.agentRenderTextures.Count; i++) { var obsTexture = ObservationToTexture( agentParameters.agentRenderTextures[i], param.cameraResolutions[camCount + i].width, param.cameraResolutions[camCount + i].height); m_Info.visualObservations.Add(obsTexture); } m_Info.reward = m_Reward; m_Info.done = m_Done; m_Info.maxStepReached = m_MaxStepReached; m_Info.id = m_Id; brain.SendState(this, m_Info); if (m_Recorder != null && m_Recorder.record) { m_Recorder.WriteExperience(m_Info); } m_Info.textObservation = ""; }