I am using Windows-Machine-Learning to convert my VideoFrame to a TensorFloat _input (shape: 1,3,256,192; RGB channels + image), load that into my onnx model and receive as _output another TensorFloat object (shape: 1,17,64,48; 17 detected objects + image).

Now my question: If I want to access that TensorFloat _output, currently the only way I know is to use _output.data.GetAsVectorView, which gives me a long 1d Vector and try to reorder that and figure out how the dimensions are ordered in there? Is there a clear rule that I can follow to understand how the 4D tensor is encoded in the 1D Vector? Alternatively, can I somehow access the different dimensions directly from the _output TensorFloat object, since using "Shape" shows me that it is a multidimensional array?

1 Answer

Please refer to the layout of Windows ML tensors here:

A tensor is a multi-dimensional array of values. A float tensor is a tensor of 32-bit floating point values.

The layout of tensors is row-major, with tightly packed contiguous data representing each dimension. The total size of a tensor is the product of the size of each dimension.

Consider:

Shape: [D1][D2][D3]...[DN] Strides: [S1][S2][S3]...[SN] Location: [A1][A2][A3]...[AN], 

and you wish to compute the index at Location.

Then, you can assume that:

Sn = Dn+1 * Dn+2 * ... * Dn, (for n = 1...N-1) SN = 1 

So:

index = A1*S1 + A2*S2 + A3*S3 + ... + AN*SN 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy