浏览代码

Assign new BrainParametersProto fields based on capabilities (#4581)

/MLA-1734-demo-provider
GitHub 4 年前
当前提交
ca1aacc1
共有 2 个文件被更改,包括 22 次插入10 次删除
  1. 3
      com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs
  2. 29
      com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs

3
com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs


{
if (NumContinuousActions > 0 && NumDiscreteActions > 0)
{
throw new UnityAgentsException("ActionSpecs must be all continuous or all discrete.");
throw new UnityAgentsException("Hybrid action spaces not supported by the trainer. " +
"ActionSpecs must be all continuous or all discrete.");
}
}
}

29
com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs


/// <param name="isTraining">Whether or not the Brain is training.</param>
public static BrainParametersProto ToBrainParametersProto(this ActionSpec actionSpec, string name, bool isTraining)
{
actionSpec.CheckNotHybrid();
if (actionSpec.NumContinuousActions > 0)
var actionSpecProto = new ActionSpecProto
brainParametersProto.VectorActionSizeDeprecated.Add(actionSpec.NumContinuousActions);
brainParametersProto.VectorActionSpaceTypeDeprecated = SpaceTypeProto.Continuous;
}
else if (actionSpec.NumDiscreteActions > 0)
NumContinuousActions = actionSpec.NumContinuousActions,
NumDiscreteActions = actionSpec.NumDiscreteActions,
DiscreteBranchSizes = { actionSpec.BranchSizes },
};
brainParametersProto.ActionSpec = actionSpecProto;
var supportHybrid = Academy.Instance.TrainerCapabilities == null || Academy.Instance.TrainerCapabilities.HybridActions;
if (!supportHybrid)
brainParametersProto.VectorActionSizeDeprecated.AddRange(actionSpec.BranchSizes);
brainParametersProto.VectorActionSpaceTypeDeprecated = SpaceTypeProto.Discrete;
actionSpec.CheckNotHybrid();
if (actionSpec.NumContinuousActions > 0)
{
brainParametersProto.VectorActionSizeDeprecated.Add(actionSpec.NumContinuousActions);
brainParametersProto.VectorActionSpaceTypeDeprecated = SpaceTypeProto.Continuous;
}
else if (actionSpec.NumDiscreteActions > 0)
{
brainParametersProto.VectorActionSizeDeprecated.AddRange(actionSpec.BranchSizes);
brainParametersProto.VectorActionSpaceTypeDeprecated = SpaceTypeProto.Discrete;
}
}
// TODO handle ActionDescriptions?

正在加载...
取消
保存