浏览代码

Address comments

/MLA-1734-demo-provider
Arthur Juliani 4 年前
当前提交
4bbe6250
共有 4 个文件被更改,包括 20 次插入24 次删除
  1. 9
      com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
  2. 7
      com.unity.ml-agents/Runtime/Sensors/ITypedSensor.cs
  3. 9
      com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs
  4. 19
      ml-agents-envs/mlagents_envs/rpc_utils.py

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


observationProto.Shape.AddRange(shape);
var typeSensor = sensor as ITypedSensor;
observationProto.SensorType = (SensorTypeProto)typeSensor.GetSensorType();
if (typeSensor != null)
{
observationProto.SensorType = (SensorTypeProto)typeSensor.GetSensorType();
}
else
{
observationProto.SensorType = SensorTypeProto.Observation;
}
return observationProto;
}

7
com.unity.ml-agents/Runtime/Sensors/ITypedSensor.cs


{
/// <summary>
/// The SensorType flag of the observation
/// The SensorType enum of the observation
[System.Flags]
public enum SensorType
internal enum SensorType
{
Observation = 0,
Goal = 1,

/// <summary>
/// Sensor interface for sensors with variable types.
/// </summary>
public interface ITypedSensor
internal interface ITypedSensor
{
/// <summary>
/// Returns the SensorType enum corresponding to the type of the sensor.

9
com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs


/// <summary>
/// A sensor implementation for vector observations.
/// </summary>
public class VectorSensor : ISensor, ITypedSensor
public class VectorSensor : ISensor
{
// TODO use float[] instead
// TODO allow setting float[]

SensorType m_sensorType;
/// <summary>
/// Initializes the sensor.

m_Observations = new List<float>(observationSize);
m_Name = name;
m_sensorType = SensorType.Observation;
m_Shape = new[] { observationSize };
}

public int[] GetObservationShape()
{
return m_Shape;
}
public SensorType GetSensorType()
{
return m_sensorType;
}
/// <inheritdoc/>

19
ml-agents-envs/mlagents_envs/rpc_utils.py


:param agent_info: protobuf object.
:return: BehaviorSpec object.
"""
observation_shape = [tuple(obs.shape) for obs in agent_info.observations]
dim_props = [
tuple(DimensionProperty(dim) for dim in obs.dimension_properties)
for obs in agent_info.observations
]
sensor_types = [SensorType(obs.sensor_type) for obs in agent_info.observations]
sensor_specs = [
SensorSpec(obs_shape, dim_p, sensor_type)
for obs_shape, dim_p, sensor_type in zip(
observation_shape, dim_props, sensor_types
sensor_specs = []
for obs in agent_info.observations:
sensor_specs.append(
SensorSpec(
tuple(obs.shape),
tuple(DimensionProperty(dim) for dim in obs.dimension_properties),
SensorType(obs.sensor_type),
)
]
# proto from communicator < v1.3 does not set action spec, use deprecated fields instead
if (
brain_param_proto.action_spec.num_continuous_actions == 0

正在加载...
取消
保存