File size: 928 Bytes
d353048 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | using Unity.InferenceEngine;
using UnityEngine.Assertions;
namespace Unity.MLAgents.Inference
{
static class DynamicTensorShapeExtensions
{
public static int[] ToArray(this DynamicTensorShape shape)
{
var shapeOut = new int[shape.rank];
// TODO investigate how critical this is and if we can just remove this assert. the alternative is to expose this again in Sentis.
// Assert.IsTrue(shape.hasRank, "ValueError: Cannot convert tensor of unknown rank to TensorShape");
var shapeArray = shape.ToIntArray();
for (var i = 0; i < shape.rank; i++)
{
if (shapeArray[i] == -1)
{
shapeOut[i] = 1;
}
else
{
shapeOut[i] = shapeArray[i];
}
}
return shapeOut;
}
}
}
|