浏览代码

ObservationSpec proposal

/v2-staging-rebase
Chris Elion 4 年前
当前提交
a05dc2a6
共有 6 个文件被更改,包括 107 次插入1 次删除
  1. 2
      com.unity.ml-agents/Runtime/Sensors/ISensor.cs
  2. 2
      com.unity.ml-agents/Runtime/Sensors/ITypedSensor.cs
  3. 8
      com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs
  4. 3
      com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs.meta
  5. 90
      com.unity.ml-agents/Runtime/Sensors/ObservationSpec.cs
  6. 3
      com.unity.ml-agents/Runtime/Sensors/ObservationSpec.cs.meta

2
com.unity.ml-agents/Runtime/Sensors/ISensor.cs


/// new {3}. A sensor that returns an RGB image would return new [] {Height, Width, 3}
/// </summary>
/// <returns>Size of the observations that will be generated.</returns>
// TODO OBSOLETE replace with GetObservationSpec.Shape
int[] GetObservationShape();
/// <summary>

/// <see cref="SensorCompressionType.None"/>.
/// </summary>
/// <returns>Compression type used by the sensor.</returns>
// TODO OBSOLETE replace with GetCompressionSpec().SensorCompressionType
SensorCompressionType GetCompressionType();
/// <summary>

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


/// <summary>
/// The ObservationType enum of the Sensor.
/// </summary>
internal enum ObservationType
public enum ObservationType
{
// Collected observations are generic.
Default = 0,

8
com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs


namespace Unity.MLAgents.Sensors
{
public struct CompressionSpec
{
public SensorCompressionType SensorCompressionType;
public int[] CompressedChannelMapping;
}
}

3
com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs.meta


fileFormatVersion: 2
guid: 30f2a27e7468474b91c9b470f8775a04
timeCreated: 1615412780

90
com.unity.ml-agents/Runtime/Sensors/ObservationSpec.cs


using Unity.Barracuda;
namespace Unity.MLAgents.Sensors
{
/// <summary>
/// This is the simplest approach, but there's possible user error if Shape.Length != DimensionProperties.Length
/// </summary>
public struct ObservationSpec
{
public ObservationType ObservationType;
public int[] Shape;
public DimensionProperty[] DimensionProperties;
/// <summary>
/// Create an Observation spec with default DimensionProperties and ObservationType from the shape.
/// </summary>
/// <param name="shape"></param>
/// <returns></returns>
public static ObservationSpec FromShape(params int[] shape)
{
DimensionProperty[] dimProps = null;
if (shape.Length == 1)
{
dimProps = new[] { DimensionProperty.None };
}
else if (shape.Length == 2)
{
// NOTE: not sure if I like this - might leave Unspecified and make BufferSensor set it
dimProps = new[] { DimensionProperty.VariableSize, DimensionProperty.None };
}
else if (shape.Length == 3)
{
dimProps = new[]
{
DimensionProperty.TranslationalEquivariance,
DimensionProperty.TranslationalEquivariance,
DimensionProperty.None
};
}
else
{
dimProps = new DimensionProperty[shape.Length];
for (var i = 0; i < dimProps.Length; i++)
{
dimProps[i] = DimensionProperty.Unspecified;
}
}
return new ObservationSpec
{
ObservationType = ObservationType.Default,
Shape = shape,
DimensionProperties = dimProps
};
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Information about a single dimension. Future per-dimension properties can go here.
/// This is nicer because it ensures the shape and dimension properties that the same size
/// </summary>
public struct DimensionInfo
{
public int Rank;
public DimensionProperty DimensionProperty;
}
public struct ObservationSpecAlternativeOne
{
public ObservationType ObservationType;
public DimensionInfo[] DimensionInfos;
// Similar ObservationSpec.FromShape() as above
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Uses Barracuda's TensorShape struct instead of an int[] for the shape.
/// This doesn't fully avoid allocations because of DimensionProperty, so we'd need more supporting code.
/// I don't like explicitly depending on Barracuda in one of our central interfaces, but listing as an alternative.
/// </summary>
public struct ObservationSpecAlternativeTwo
{
public ObservationType ObservationType;
public TensorShape Shape;
public DimensionProperty[] DimensionProperties;
}
}

3
com.unity.ml-agents/Runtime/Sensors/ObservationSpec.cs.meta


fileFormatVersion: 2
guid: cc1734d60fd5485ead94247cb206aa35
timeCreated: 1615412644
正在加载...
取消
保存