浏览代码

Use original behavior name on subsequent reset (#5356)

/colab-links
GitHub 4 年前
当前提交
0b578419
共有 1 个文件被更改,包括 23 次插入6 次删除
  1. 29
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs

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


string m_BehaviorNameOverrideDirectory;
private string m_OriginalBehaviorName;
private List<string> m_OverrideExtensions = new List<string>();
// Cached loaded NNModels, with the behavior name as the key.

{
GetAssetPathFromCommandLine();
return !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory);
}
}
/// <summary>
/// The original behavior name of the agent. The actual behavior name will change when it is overridden.
/// </summary>
public string OriginalBehaviorName
{
get
{
if (string.IsNullOrEmpty(m_OriginalBehaviorName))
{
var bp = m_Agent.GetComponent<BehaviorParameters>();
m_OriginalBehaviorName = bp.BehaviorName;
}
return m_OriginalBehaviorName;
}
}

string overrideError = null;
m_Agent.LazyInitialize();
var bp = m_Agent.GetComponent<BehaviorParameters>();
var behaviorName = bp.BehaviorName;
nnModel = GetModelForBehaviorName(behaviorName);
nnModel = GetModelForBehaviorName(OriginalBehaviorName);
}
catch (Exception e)
{

if (string.IsNullOrEmpty(overrideError))
{
overrideError =
$"Didn't find a model for behaviorName {behaviorName}. Make " +
$"Didn't find a model for behaviorName {OriginalBehaviorName}. Make " +
"sure the behaviorName is set correctly in the commandline " +
"and that the model file exists";
}

var modelName = nnModel != null ? nnModel.name : "<null>";
Debug.Log($"Overriding behavior {behaviorName} for agent with model {modelName}");
Debug.Log($"Overriding behavior {OriginalBehaviorName} for agent with model {modelName}");
m_Agent.SetModel(GetOverrideBehaviorName(behaviorName), nnModel);
m_Agent.SetModel(GetOverrideBehaviorName(OriginalBehaviorName), nnModel);
overrideOk = true;
}
catch (Exception e)

正在加载...
取消
保存