class TensorDescriptor(ctypes.Structure)

Info Value
Package mvnc
Module mvncapi
Version 2.0
See also Graph, Fifo, GraphOption, FifoOption, Graph.get_option(), Fifo.get_option()

TensorDescriptor is a structure that describes graph inputs and outputs.

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

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

Notes

Examples

Example 1: Get the input tensor descriptor list from a Graph.

import mvnc.mvncapi as mvnc

# Create and open a device and create and allocate a graph...

# Get a list of input TensorDescriptor objects from the graph
inputDescs = graph.get_option(mvnc.GraphOption.RO_INPUT_TENSOR_DESCRIPTORS)

...

Example 2: Create and set a channel-minor host tensor descriptor for an input Fifo.

import mvnc.mvncapi as mvnc

# Create and open a device and create and allocate a graph with fifos...

# 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
host_tensor_descriptor = fifoIn.get_option(mvnc.FifoOption.RO_GRAPH_TENSOR_DESCRIPTOR)

# Set the tensor data type
host_tensor_descriptor.dataType = mvnc.FifoDataType.FP32.value

# 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
host_tensor_descriptor.cStride = 4
host_tensor_descriptor.wStride = host_tensor_descriptor.cStride * host_tensor_descriptor.c
host_tensor_descriptor.hStride = host_tensor_descriptor.wStride * host_tensor_descriptor.w
host_tensor_descriptor.totalSize = host_tensor_descriptor.hStride * host_tensor_descriptor.h

# Set the option
fifoIn.set_option(mvnc.FifoOption.RW_HOST_TENSOR_DESCRIPTOR, host_tensor_descriptor)

...