Convert Texture to Tensor without the Batch dimension

I have the following code for converting a Texture into a Tensor

var transform = new TextureTransform();
transform.SetDimensions(size, size, 3);
TensorFloat image = TextureConverter.ToTensor(source, transform);

Output tensor is of the size (1 ,3, 640, 640)
I want to remove the initial dimension and get a (3, 640,640,) tensor.
How can I achieve that?

1 Like

You should be able to remove the first dimension by reshaping the tensor in one of the following ways:
image.Reshape(image.shape.Squeeze());
or
image.Reshape(image.shape.Reduce(0, keepDim: false));

1 Like