浏览代码

BehaviorParameters - accessors for undecorated behavior name (#3316)

* BehaviorParameters - accessors for undecorated behavior name

* one fully-qualified is enough
/asymm-envs
GitHub 5 年前
当前提交
5c192cb5
共有 4 个文件被更改,包括 18 次插入13 次删除
  1. 9
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  2. 2
      com.unity.ml-agents/Runtime/DemonstrationRecorder.cs
  3. 10
      com.unity.ml-agents/Runtime/Policy/BehaviorParameters.cs
  4. 10
      com.unity.ml-agents/Runtime/Policy/RemotePolicy.cs

9
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs


void GetAssetPathFromCommandLine()
{
m_BehaviorNameOverrides.Clear();
m_BehaviorNameOverrides["3DBall"] = "/Users/chris.elion/code/ml-agents/models/ppo/3DBall.nn"; // TODO REMOVE ME
var args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length-2; i++)

agent.LazyInitialize();
var bp = agent.GetComponent<BehaviorParameters>();
var behaviorNameAndTeamId = bp.behaviorName;
var behaviorName = behaviorNameAndTeamId.Split('?')[0];
var nnModel = GetModelForBehaviorName(behaviorName);
Debug.Log($"Overriding behavior {behaviorName} for agent with model {nnModel?.name}");
var nnModel = GetModelForBehaviorName(bp.behaviorName);
Debug.Log($"Overriding behavior {bp.behaviorName} for agent with model {nnModel?.name}");
agent.GiveModel($"Override_{behaviorName}", nnModel, InferenceDevice.CPU);
agent.GiveModel($"Override_{bp.behaviorName}", nnModel, InferenceDevice.CPU);
}
}

2
com.unity.ml-agents/Runtime/DemonstrationRecorder.cs


m_DemoStore.Initialize(
demonstrationName,
behaviorParams.brainParameters,
behaviorParams.behaviorName);
behaviorParams.fullyQualifiedBehaviorName);
Monitor.Log("Recording Demonstration of Agent: ", m_RecordingAgent.name);
}

10
com.unity.ml-agents/Runtime/Policy/BehaviorParameters.cs


public string behaviorName
{
get { return m_BehaviorName;}
}
/// <summary>
/// Returns the behavior name, concatenated with any other metadata (i.e. team id).
/// </summary>
public string fullyQualifiedBehaviorName
{
get { return m_BehaviorName + "?team=" + m_TeamID;}
}

case BehaviorType.Default:
if (Academy.Instance.IsCommunicatorOn)
{
return new RemotePolicy(m_BrainParameters, behaviorName);
return new RemotePolicy(m_BrainParameters, fullyQualifiedBehaviorName);
}
if (m_Model != null)
{

10
com.unity.ml-agents/Runtime/Policy/RemotePolicy.cs


/// </summary>
public class RemotePolicy : IPolicy
{
string m_BehaviorName;
string m_FullyQualifiedBehaviorName;
protected ICommunicator m_Communicator;
/// <summary>

/// <inheritdoc />
public RemotePolicy(
BrainParameters brainParameters,
string behaviorName)
string fullyQualifiedBehaviorName)
m_BehaviorName = behaviorName;
m_FullyQualifiedBehaviorName = fullyQualifiedBehaviorName;
m_Communicator.SubscribeBrain(m_BehaviorName, brainParameters);
m_Communicator.SubscribeBrain(m_FullyQualifiedBehaviorName, brainParameters);
m_Communicator?.PutObservations(m_BehaviorName, info, sensors, action);
m_Communicator?.PutObservations(m_FullyQualifiedBehaviorName, info, sensors, action);
}
/// <inheritdoc />

正在加载...
取消
保存