浏览代码

cleanup

/ai-hw-2021
Ruo-Ping Dong 4 年前
当前提交
bca98dc1
共有 4 个文件被更改,包括 3 次插入47 次删除
  1. 2
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  2. 7
      com.unity.ml-agents/Runtime/Policies/TrainingModelRunner.cs
  3. 36
      com.unity.ml-agents/Runtime/Policies/TrainingPolicy.cs
  4. 5
      com.unity.ml-agents/Runtime/Trainer.cs

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


return new BarracudaPolicy(actionSpec, actuatorManager, m_Model, m_InferenceDevice, m_BehaviorName);
}
case BehaviorType.InEditorTraining:
return new TrainingPolicy(actionSpec, actuatorManager, m_BehaviorName);
return new TrainingPolicy(actionSpec, m_BehaviorName);
case BehaviorType.Default:
if (Academy.Instance.IsCommunicatorOn)
{

7
com.unity.ml-agents/Runtime/Policies/TrainingModelRunner.cs


// ModelRunner for C# training.
using System;
using System.Collections.Generic;
using Unity.Barracuda;

m_Infos.Clear();
m_OrderedAgentsRequestingDecisions.Clear();
}
public bool HasModel(NNModel other, InferenceDevice otherInferenceDevice)
{
return m_Model == other && m_InferenceDevice == otherInferenceDevice;
}
public ActionBuffers GetAction(int agentId)

36
com.unity.ml-agents/Runtime/Policies/TrainingPolicy.cs


namespace Unity.MLAgents.Policies
{
/// <summary>
/// The Barracuda Policy uses a Barracuda Model to make decisions at
/// every step. It uses a ModelRunner that is shared across all
/// Barracuda Policies that use the same model and inference devices.
/// </summary>
internal class TrainingPolicy : IPolicy
{
protected TrainingModelRunner m_ModelRunner;

/// <summary>
/// Sensor shapes for the associated Agents. All Agents must have the same shapes for their Sensors.
/// </summary>
List<int[]> m_SensorShapes;
/// <summary>
/// List of actuators, only used for analytics
/// </summary>
private IList<IActuator> m_Actuators;
/// <summary>
/// Whether or not we've tried to send analytics for this model. We only ever try to send once per policy,
/// and do additional deduplication in the analytics code.
/// </summary>
private bool m_AnalyticsSent;
private AgentInfo m_LastInfo;
IList<IActuator> actuators,
string behaviorName
)
{

m_Actuators = actuators;
if (!m_AnalyticsSent)
{
m_AnalyticsSent = true;
Analytics.InferenceAnalytics.InferenceModelSet(
m_ModelRunner.Model,
m_BehaviorName,
m_ModelRunner.InferenceDevice,
sensors,
m_ActionSpec,
m_Actuators
);
}
m_AgentId = info.episodeId;
m_ModelRunner?.PutObservations(info, sensors);
}

5
com.unity.ml-agents/Runtime/Trainer.cs


// Trainer for C# training. One trainer per behavior.
using System;
using System.Collections.Generic;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.Inference;
namespace Unity.MLAgents

正在加载...
取消
保存