浏览代码

Merge pull request #3627 from Unity-Technologies/release-0.15.0-log-no-model

[MLA-762] Better logging when no model + inference only
/release-0.15.0
GitHub 5 年前
当前提交
9b227be2
共有 6 个文件被更改,包括 66 次插入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. 2
      com.unity.ml-agents/Tests/Editor/PublicAPI/PublicApiValidation.cs
  5. 29
      com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs
  6. 11
      com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs.meta

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)
{

2
com.unity.ml-agents/Tests/Editor/PublicAPI/PublicApiValidation.cs


var agent = gameObject.AddComponent<PublicApiAgent>();
// Make sure we can set the behavior type correctly after the agent is added
behaviorParams.behaviorType = BehaviorType.InferenceOnly;
// Can't actually create an Agent with InferenceOnly and no model, so change back
behaviorParams.behaviorType = BehaviorType.Default;
// TODO - not internal yet
// var decisionRequester = gameObject.AddComponent<DecisionRequester>();

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);
});
}
}
}

11
com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs.meta


fileFormatVersion: 2
guid: 877266b9e1bfe4330a68ab5f2da1836b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存