Graph.allocate_with_fifos()
Info | Value |
---|---|
Package | mvnc |
Module | mvncapi |
Version | 2.0 |
See also | Device, Graph, Fifo, Graph.allocate() |
Overview
This method allocates a network graph to the device and creates and allocates two associated Fifos for graph input and output. This is a convenient way to set up a Graph for inference without setting up Fifos explicitly. Each Graph instance can only be allocated to a single Device instance.
Upon successful return from this method, the Graph will be ready to perform inferences and the input and output Fifos will be ready for reading/writing.
Calling Graph.destroy() for the Graph and Fifo.destroy() for each Fifo frees the memory allocated with this method.
Syntax
input_fifo, output_fifo = graph.allocate_with_fifos(
device, graph_buffer,
input_fifo_type=mvncapi.FifoType.HOST_WO,
input_fifo_num_elem=2,
input_fifo_data_type=mvncapi.FifoDataType.FP32,
output_fifo_type=mvncapi.FifoType.HOST_RO,
output_fifo_num_elem=2,
output_fifo_data_type=mvncapi.FifoDataType.FP32
)
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
device | Device | A Device that this Graph will be allocated to. The DeviceState must be OPENED. | |
graph_buffer | bytes | Raw data read from a neural network graph file that was created with the Intel® Movidius™ Neural Compute SDK mvNCCompile tool. | |
input_fifo_type | int | FifoType.HOST_WO | A member of the FifoType enumeration, which sets read/write access to the Fifo. |
input_fifo_num_elem | int | 2 | The maximum number of elements that the input Fifo can hold. |
input_fifo_data_type | int | FifoDataType.FP32 | A member of the FifoDataType enumeration. |
output_fifo_type | int | FifoType.HOST_RO | A member of the FifoType enumeration, which sets read/write access to the Fifo. |
output_fifo_num_elem | int | 2 | The maximum number of elements that the output Fifo can hold. |
output_fifo_data_type | int | FifoDataType.FP32 | A member of the FifoDataType enumeration. |
Return
The input and output Fifos that were created and allocated by this method.
Raises
Exception with a status code from Status if underlying function calls return a status other than Status.OK.
Notes
- This method takes the place of explicit calls for Graph.allocate(), Fifo creation, and Fifo.allocate().
Example
from mvnc import mvncapi
# Get a list of valid device identifiers
device_list = mvncapi.enumerate_devices()
# Create a Device instance for the first device found
device = mvncapi.Device(device_list[0])
# Open communication with the device
device.open()
# Create a Graph
graph = mvncapi.Graph('graph1')
# Read a compiled network graph from file (set the graph_filepath correctly for your graph file)
graph_filepath = './graph'
with open(graph_filepath, 'rb') as f:
graph_buffer = f.read()
# Allocate the graph on the device
input_fifo, output_fifo = graph.allocate_with_fifos(device, graph_buffer)
#
# Use the device...
#
# Deallocate and destroy the graph handle and fifo handles, close the device, and destroy the device handle
input_fifo.destroy()
output_fifo.destroy()
graph.destroy()
device.close()
device.destroy()