struct ncTensorDescriptor_t

Info Value
Header mvnc.h
Version 2.0
See also struct ncGraphHandle_t, struct ncFifoHandle_t, ncGraphOption_t, ncFifoOption_t, ncGraphGetOption(), ncFifoGetOption()

Overview

The ncTensorDescriptor_t struct describes graph inputs and outputs.

Member Type Description
n unsigned int The number of tensors in the batch.

Only 1 currently supported.
c unsigned int For image tensors, this is the number of channels per pixel. For non-image tensors, this is always 1.
w unsigned int For image tensors, this is the width in pixels. For non-image tensors, this is always 1.
h unsigned int The height of the tensor. For non-image tensors, this is always 1.
totalSize unsigned int For image tensors, this is the height in pixels. For non-image tensors, this is always 1.
cStride unsigned int Stride (distance between elements in bytes) in the channel dimension.
wStride unsigned int Stride (distance between elements in bytes) in the horizontal dimension.
hStride unsigned int Stride (distance between elements in bytes) in the vertical dimension.
dataType ncFifoDataType_t The tensor’s data type (FP16 or FP32).

Notes

  • You can use ncGraphGetOption() to get arrays of input or output ncTensorDescriptor_t structs for a graph.
  • If your application’s input tensor is not in a channel minor format (i.e. RGB/BGR), you can create a ncTensorDescriptor struct with appropriate values for the stride fields and pass it to ncFifoSetOption() for NC_RW_HOST_TENSOR_DESCRIPTOR. This currently cannot be used to perform scaling (n/c/h/w fields must match those in the NC_RO_GRAPH_TENSOR_DESCRIPTOR for this FIFO. See the examples below.

Examples

... 

// The n/c/w/h fields for the RW_HOST_TENSOR_DESCRIPTOR must match the dimensions of the RO_GRAPH_TENSOR_DESCRIPTOR, so start with that
struct ncTensorDescriptor_t inputTensorDesc;
unsigned int length = sizeof(struct ncTensorDescriptor_t);
ncGraphGetOption(graphHandle, NC_RO_GRAPH_INPUT_TENSOR_DESCRIPTORS, &inputTensorDesc,  &length);
struct ncTensorDescriptor_t hostTensorDesc = inputTensorDesc;

// Set the tensor data type
hostTensorDesc.dataType = NC_FIFO_FP32;

// For channel-minor data with FP32 data type, there are 4 bytes between each element of the channel
// The horizontal stride (wStride), vertical stride (hStride), and totalSize can be calculated from there
hostTensorDesc.cStride = sizeof(float); //FP32
hostTensorDesc.wStride = hostTensorDesc.cStride * hostTensorDesc.c;
hostTensorDesc.hStride = hostTensorDesc.wStride * hostTensorDesc.w;
hostTensorDesc.totalSize = hostTensorDesc.hStride * hostTensorDesc.h;

// Set the option
length = sizeof(struct ncTensorDescriptor_t);
ncFifoSetOption(bufferIn, NC_RW_FIFO_HOST_TENSOR_DESCRIPTOR, &hostTensorDesc, length);

...