浏览代码

Improve warnings and exception if using unsupported combo

/bug-failed-api-check
Chris Elion 5 年前
当前提交
7df92fbe
共有 4 个文件被更改,包括 53 次插入5 次删除
  1. 3
      com.unity.ml-agents/Editor/BehaviorParametersEditor.cs
  2. 16
      com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
  3. 10
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  4. 29
      com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs

3
com.unity.ml-agents/Editor/BehaviorParametersEditor.cs


if (brainParameters != null)
{
var failedChecks = Inference.BarracudaModelParamLoader.CheckModel(
barracudaModel, brainParameters, sensorComponents);
barracudaModel, brainParameters, sensorComponents, behaviorParameters.behaviorType
);
foreach (var check in failedChecks)
{
if (check != null)

16
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs


/// </param>
/// <param name="sensorComponents">Attached sensor components</param>
/// <returns>The list the error messages of the checks that failed</returns>
public static IEnumerable<string> CheckModel(Model model, BrainParameters brainParameters, SensorComponent[] sensorComponents)
public static IEnumerable<string> CheckModel(Model model, BrainParameters brainParameters,
SensorComponent[] sensorComponents, BehaviorType behaviorType = BehaviorType.Default)
failedModelChecks.Add(
"There is no model for this Brain, cannot run inference. " +
"(But can still train)");
var errorMsg = "There is no model for this Brain; cannot run inference. ";
if (behaviorType == BehaviorType.InferenceOnly)
{
errorMsg += "Either assign a model, or change to a different Behavior Type.";
}
else
{
errorMsg += "(But can still train)";
}
failedModelChecks.Add(errorMsg);
return failedModelChecks;
}

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


case BehaviorType.HeuristicOnly:
return new HeuristicPolicy(heuristic);
case BehaviorType.InferenceOnly:
{
if (m_Model == null)
{
var behaviorType = BehaviorType.InferenceOnly.ToString();
throw new UnityAgentsException(
$"Can't use Behavior Type {behaviorType} without a model. " +
"Either assign a model, or change to a different Behavior Type."
);
}
}
case BehaviorType.Default:
if (Academy.Instance.IsCommunicatorOn)
{

29
com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs


using NUnit.Framework;
using UnityEngine;
using MLAgents;
using MLAgents.Policies;
namespace MLAgents.Tests
{
[TestFixture]
public class BehaviorParameterTests
{
static float[] DummyHeuristic()
{
return null;
}
[Test]
public void TestNoModelInferenceOnlyThrows()
{
var gameObj = new GameObject();
var bp = gameObj.AddComponent<BehaviorParameters>();
bp.behaviorType = BehaviorType.InferenceOnly;
Assert.Throws<UnityAgentsException>(() =>
{
bp.GeneratePolicy(DummyHeuristic);
});
}
}
}
正在加载...
取消
保存