/// <summary> /// Converts a AgentInfo to a protobuf generated AgentInfoProto /// </summary> /// <returns>The protobuf version of the AgentInfo.</returns> public static AgentInfoProto ToAgentInfoProto(this AgentInfo ai) { if (ai.groupId > 0) { var trainerCanHandle = Academy.Instance.TrainerCapabilities == null || Academy.Instance.TrainerCapabilities.MultiAgentGroups; if (!trainerCanHandle) { if (!s_HaveWarnedTrainerCapabilitiesAgentGroup) { Debug.LogWarning( $"Attached trainer doesn't support Multi Agent Groups; group rewards will be ignored." + "Please find the versions that work best together from our release page: " + "https://github.com/Unity-Technologies/ml-agents/releases" ); s_HaveWarnedTrainerCapabilitiesAgentGroup = true; } } } var agentInfoProto = new AgentInfoProto { Reward = ai.reward, GroupReward = ai.groupReward, MaxStepReached = ai.maxStepReached, Done = ai.done, Id = ai.episodeId, GroupId = ai.groupId, }; if (ai.discreteActionMasks != null) { agentInfoProto.ActionMask.AddRange(ai.discreteActionMasks); } return(agentInfoProto); }
/// <summary> /// Converts a AgentInfo to a protobuf generated AgentInfoProto /// </summary> /// <returns>The protobuf version of the AgentInfo.</returns> public static AgentInfoProto ToProto(this AgentInfo ai) { var agentInfoProto = new AgentInfoProto { StackedVectorObservation = { ai.stackedVectorObservation }, StoredVectorActions = { ai.storedVectorActions }, StoredTextActions = ai.storedTextActions, TextObservation = ai.textObservation, Reward = ai.reward, MaxStepReached = ai.maxStepReached, Done = ai.done, Id = ai.id, CustomObservation = ai.customObservation }; if (ai.memories != null) { agentInfoProto.Memories.Add(ai.memories); } if (ai.actionMasks != null) { agentInfoProto.ActionMask.AddRange(ai.actionMasks); } if (ai.compressedObservations != null) { foreach (var obs in ai.compressedObservations) { agentInfoProto.CompressedObservations.Add(obs.ToProto()); } } return(agentInfoProto); }
/// <summary> /// Converts a AgentInfo to a protobuf generated AgentInfoProto /// </summary> /// <returns>The protobuf version of the AgentInfo.</returns> public static AgentInfoProto ToAgentInfoProto(this AgentInfo ai, List <Observation> observations) { var agentInfoProto = new AgentInfoProto { Reward = ai.reward, MaxStepReached = ai.maxStepReached, Done = ai.done, Id = ai.id, }; if (ai.actionMasks != null) { agentInfoProto.ActionMask.AddRange(ai.actionMasks); } if (observations != null) { foreach (var obs in observations) { agentInfoProto.Observations.Add(obs.ToProto()); } } return(agentInfoProto); }
/// <summary> /// Converts a AgentInfo to a protobuffer generated AgentInfoProto /// </summary> /// <returns>The protobuf version of the AgentInfo.</returns> public AgentInfoProto ToProto() { var agentInfoProto = new AgentInfoProto { StackedVectorObservation = { stackedVectorObservation }, StoredVectorActions = { storedVectorActions }, StoredTextActions = storedTextActions, TextObservation = textObservation, Reward = reward, MaxStepReached = maxStepReached, Done = done, Id = id, CustomObservation = customObservation }; if (memories != null) { agentInfoProto.Memories.Add(memories); } if (actionMasks != null) { agentInfoProto.ActionMask.AddRange(actionMasks); } foreach (var obs in visualObservations) { agentInfoProto.VisualObservations.Add( ByteString.CopyFrom(obs.EncodeToPNG()) ); } return(agentInfoProto); }
/// <summary> /// Converts a AgentInfo to a protobuf generated AgentInfoProto /// </summary> /// <returns>The protobuf version of the AgentInfo.</returns> public static AgentInfoProto ToAgentInfoProto(this AgentInfo ai) { var agentInfoProto = new AgentInfoProto { Reward = ai.reward, MaxStepReached = ai.maxStepReached, Done = ai.done, Id = ai.episodeId, }; if (ai.discreteActionMasks != null) { agentInfoProto.ActionMask.AddRange(ai.discreteActionMasks); } return(agentInfoProto); }
AgentInfoConvertor(AgentInfo info) { var agentInfoProto = new AgentInfoProto { StackedVectorObservation = { info.stackedVectorObservation }, StoredVectorActions = { info.storedVectorActions }, Memories = { info.memories }, StoredTextActions = info.storedTextActions, TextObservation = info.textObservation, Reward = info.reward, MaxStepReached = info.maxStepReached, Done = info.done, Id = info.id }; foreach (var obs in info.visualObservations) { agentInfoProto.VisualObservations.Add( ByteString.CopyFrom(obs.EncodeToJPG()) ); } return(agentInfoProto); }