|
|
|
|
|
|
int m_UnstackedObservationSize; |
|
|
|
|
|
|
|
string m_Name; |
|
|
|
int[] m_Shape; |
|
|
|
int[] m_WrappedShape; |
|
|
|
private ObservationSpec m_ObservationSpec; |
|
|
|
private ObservationSpec m_WrappedSpec; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Buffer of previous observations
|
|
|
|
|
|
|
|
|
|
|
m_Name = $"StackingSensor_size{numStackedObservations}_{wrapped.GetName()}"; |
|
|
|
|
|
|
|
m_WrappedShape = wrapped.GetObservationShape(); |
|
|
|
m_Shape = new int[m_WrappedShape.Length]; |
|
|
|
m_WrappedSpec = wrapped.GetObservationSpec(); |
|
|
|
m_ObservationSpec = m_WrappedSpec.Clone(); |
|
|
|
for (int d = 0; d < m_WrappedShape.Length; d++) |
|
|
|
{ |
|
|
|
m_Shape[d] = m_WrappedShape[d]; |
|
|
|
} |
|
|
|
m_Shape[m_Shape.Length - 1] *= numStackedObservations; |
|
|
|
m_ObservationSpec.Shape[m_ObservationSpec.Shape.Length - 1] *= numStackedObservations; |
|
|
|
|
|
|
|
// Initialize uncompressed buffer anyway in case python trainer does not
|
|
|
|
// support the compression mapping and has to fall back to uncompressed obs.
|
|
|
|
|
|
|
m_CompressionMapping = ConstructStackedCompressedChannelMapping(wrapped); |
|
|
|
} |
|
|
|
|
|
|
|
if (m_Shape.Length != 1) |
|
|
|
if (m_WrappedSpec.Shape.Length != 1) |
|
|
|
m_tensorShape = new TensorShape(0, m_WrappedShape[0], m_WrappedShape[1], m_WrappedShape[2]); |
|
|
|
var wrappedShape = m_WrappedSpec.Shape; |
|
|
|
m_tensorShape = new TensorShape(0, wrappedShape[0], wrappedShape[1], wrappedShape[2]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
// First, call the wrapped sensor's write method. Make sure to use our own writer, not the passed one.
|
|
|
|
m_LocalWriter.SetTarget(m_StackedObservations[m_CurrentIndex], m_WrappedShape, 0); |
|
|
|
m_LocalWriter.SetTarget(m_StackedObservations[m_CurrentIndex], m_WrappedSpec.Shape, 0); |
|
|
|
if (m_WrappedShape.Length == 1) |
|
|
|
if (m_WrappedSpec.Shape.Length == 1) |
|
|
|
{ |
|
|
|
for (var i = 0; i < m_NumStackedObservations; i++) |
|
|
|
{ |
|
|
|
|
|
|
for (var i = 0; i < m_NumStackedObservations; i++) |
|
|
|
{ |
|
|
|
var obsIndex = (m_CurrentIndex + 1 + i) % m_NumStackedObservations; |
|
|
|
for (var h = 0; h < m_WrappedShape[0]; h++) |
|
|
|
for (var h = 0; h < m_WrappedSpec.Shape[0]; h++) |
|
|
|
for (var w = 0; w < m_WrappedShape[1]; w++) |
|
|
|
for (var w = 0; w < m_WrappedSpec.Shape[1]; w++) |
|
|
|
for (var c = 0; c < m_WrappedShape[2]; c++) |
|
|
|
for (var c = 0; c < m_WrappedSpec.Shape[2]; c++) |
|
|
|
writer[h, w, i * m_WrappedShape[2] + c] = m_StackedObservations[obsIndex][m_tensorShape.Index(0, h, w, c)]; |
|
|
|
writer[h, w, i * m_WrappedSpec.Shape[2] + c] = m_StackedObservations[obsIndex][m_tensorShape.Index(0, h, w, c)]; |
|
|
|
numWritten = m_WrappedShape[0] * m_WrappedShape[1] * m_WrappedShape[2] * m_NumStackedObservations; |
|
|
|
numWritten = m_WrappedSpec.Shape[0] * m_WrappedSpec.Shape[1] * m_WrappedSpec.Shape[2] * m_NumStackedObservations; |
|
|
|
} |
|
|
|
|
|
|
|
return numWritten; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public int[] GetObservationShape() |
|
|
|
public ObservationSpec GetObservationSpec() |
|
|
|
return m_Shape; |
|
|
|
return m_ObservationSpec; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
internal byte[] CreateEmptyPNG() |
|
|
|
{ |
|
|
|
int height = m_WrappedSensor.GetObservationShape()[0]; |
|
|
|
int width = m_WrappedSensor.GetObservationShape()[1]; |
|
|
|
var shape = m_WrappedSpec.Shape; |
|
|
|
int height = shape[0]; |
|
|
|
int width = shape[1]; |
|
|
|
var texture2D = new Texture2D(width, height, TextureFormat.RGB24, false); |
|
|
|
Color32[] resetColorArray = texture2D.GetPixels32(); |
|
|
|
Color32 black = new Color32(0, 0, 0, 0); |
|
|
|
|
|
|
// wrapped sensor doesn't have one, use default mapping.
|
|
|
|
// Default mapping: {0, 0, 0} for grayscale, identity mapping {1, 2, ..., n} otherwise.
|
|
|
|
int[] wrappedMapping = null; |
|
|
|
int wrappedNumChannel = wrappedSenesor.GetObservationShape()[2]; |
|
|
|
int wrappedNumChannel = m_WrappedSpec.Shape[2]; |
|
|
|
var sparseChannelSensor = m_WrappedSensor as ISparseChannelSensor; |
|
|
|
if (sparseChannelSensor != null) |
|
|
|
{ |
|
|
|