-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MLA-488] Fix observations in demonstration drawer #3771
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ namespace MLAgents | |
{ | ||
internal static class GrpcExtensions | ||
{ | ||
#region AgentInfo | ||
/// <summary> | ||
/// Converts a AgentInfo to a protobuf generated AgentInfoActionPairProto | ||
/// </summary> | ||
|
@@ -59,6 +60,24 @@ public static AgentInfoProto ToAgentInfoProto(this AgentInfo ai) | |
return agentInfoProto; | ||
} | ||
|
||
public static List<ObservationSummary> GetObservationSummaries(this AgentInfoActionPairProto infoActionPair) | ||
chriselion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
List<ObservationSummary> summariesOut = new List<ObservationSummary>(); | ||
var agentInfo = infoActionPair.AgentInfo; | ||
foreach (var obs in agentInfo.Observations) | ||
{ | ||
var summary = new ObservationSummary(); | ||
summary.shape = obs.Shape.ToArray(); | ||
summariesOut.Add(summary); | ||
} | ||
|
||
return summariesOut; | ||
} | ||
|
||
|
||
#endregion | ||
|
||
#region BrainParameters | ||
/// <summary> | ||
/// Converts a Brain into to a Protobuf BrainInfoProto so it can be sent | ||
/// </summary> | ||
|
@@ -80,6 +99,25 @@ public static BrainParametersProto ToProto(this BrainParameters bp, string name, | |
return brainParametersProto; | ||
} | ||
|
||
/// <summary> | ||
/// Convert a BrainParametersProto to a BrainParameters struct. | ||
/// </summary> | ||
/// <param name="bpp">An instance of a brain parameters protobuf object.</param> | ||
/// <returns>A BrainParameters struct.</returns> | ||
public static BrainParameters ToBrainParameters(this BrainParametersProto bpp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just moved this closer to the BrainParameters -> BrainParametersProto conversion |
||
{ | ||
var bp = new BrainParameters | ||
{ | ||
vectorActionSize = bpp.VectorActionSize.ToArray(), | ||
vectorActionDescriptions = bpp.VectorActionDescriptions.ToArray(), | ||
vectorActionSpaceType = (SpaceType)bpp.VectorActionSpaceType | ||
}; | ||
return bp; | ||
} | ||
|
||
#endregion | ||
|
||
#region DemonstrationMetaData | ||
/// <summary> | ||
/// Convert metadata object to proto object. | ||
/// </summary> | ||
|
@@ -114,22 +152,7 @@ public static DemonstrationMetaData ToDemonstrationMetaData(this DemonstrationMe | |
} | ||
return dm; | ||
} | ||
|
||
/// <summary> | ||
/// Convert a BrainParametersProto to a BrainParameters struct. | ||
/// </summary> | ||
/// <param name="bpp">An instance of a brain parameters protobuf object.</param> | ||
/// <returns>A BrainParameters struct.</returns> | ||
public static BrainParameters ToBrainParameters(this BrainParametersProto bpp) | ||
{ | ||
var bp = new BrainParameters | ||
{ | ||
vectorActionSize = bpp.VectorActionSize.ToArray(), | ||
vectorActionDescriptions = bpp.VectorActionDescriptions.ToArray(), | ||
vectorActionSpaceType = (SpaceType)bpp.VectorActionSpaceType | ||
}; | ||
return bp; | ||
} | ||
#endregion | ||
|
||
public static UnityRLInitParameters ToUnityRLInitParameters(this UnityRLInitializationInputProto inputProto) | ||
{ | ||
|
@@ -141,6 +164,7 @@ public static UnityRLInitParameters ToUnityRLInitParameters(this UnityRLInitiali | |
}; | ||
} | ||
|
||
#region AgentAction | ||
public static AgentAction ToAgentAction(this AgentActionProto aap) | ||
{ | ||
return new AgentAction | ||
|
@@ -158,7 +182,9 @@ public static List<AgentAction> ToAgentActionList(this UnityRLInputProto.Types.L | |
} | ||
return agentActions; | ||
} | ||
#endregion | ||
|
||
#region Observations | ||
public static ObservationProto ToProto(this Observation obs) | ||
{ | ||
ObservationProto obsProto = null; | ||
|
@@ -248,5 +274,6 @@ public static ObservationProto GetObservationProto(this ISensor sensor, WriteAda | |
observationProto.Shape.AddRange(shape); | ||
return observationProto; | ||
} | ||
#endregion | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
com.unity.ml-agents/Runtime/Demonstrations/Demonstration.cs
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
com.unity.ml-agents/Runtime/Demonstrations/DemonstrationMetaData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using UnityEngine; | ||
using MLAgents.Policies; | ||
|
||
namespace MLAgents.Demonstrations | ||
{ | ||
/// <summary> | ||
/// Demonstration meta-data. | ||
/// Kept in a struct for easy serialization and deserialization. | ||
/// </summary> | ||
[Serializable] | ||
internal class DemonstrationMetaData | ||
{ | ||
public int numberExperiences; | ||
public int numberEpisodes; | ||
public float meanReward; | ||
public string demonstrationName; | ||
public const int ApiVersion = 1; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.ml-agents/Runtime/Demonstrations/DemonstrationMetaData.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this variable used ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure about the purpose of it. It sets this field https://docs.unity3d.com/ScriptReference/AssetImporter-userData.html which explains the .meta file changes.