/// <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(); CollectObservations(); 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(); 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.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(); /// 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 = ""; }