class Graph

Info Value
Package mvnc
Module mvncapi
Version 2.0
See also GraphOption, Device, Fifo, Graph.allocate(), Graph.allocate_with_fifos()

Overview

The Graph class represents a neural network graph and provides methods to perform inferences.

Create and allocate a Graph for each network graph file. A Device can have more than one Graph allocated to it, but each Graph can only be allocated to a single Device.

Initialization

Create a Graph instance:

graph = mvncapi.Graph(name)
Parameter Type Description
name str A name for the graph; this can be anything you like up to mvncapi.MAX_NAME_SIZE characters, or just an empty string.

The name can be retrieved later with Graph.get_option().

When the Graph has been successfully created, the GraphState will be CREATED.

Methods

Method Description
allocate Allocate a Graph to a device.
allocate_with_fifos Allocate a graph to a device and create and allocate associated Fifos.
destroy Deallocate a graph that was allocated with Graph.allocate().
get_option Get the value of a graph option.

See GraphOption.
queue_inference Queue an inference to be processed by the graph.
queue_inference_with_fifo_elem Write input tensor data to an input Fifo buffer and then trigger graph execution.
set_option Set the value of a graph option.

See GraphOption.

Typical Usage

See the Python API Overview for more information about typical API usage.

Examples

from mvnc import mvncapi

#
# Create and open a Device...
#

# 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 and create input and output Fifos
input_fifo, output_fifo = graph.allocate_with_fifos(device, graph_buffer)

#
# Pre-procces your input tensor...
#

# Write the tensor to the input Fifo and queue an inference
graph.queue_inference_with_fifo_elem(input_fifo, output_fifo, input_tensor, None, 'object1')

#
# Read the output from the output_fifo and use it as needed...
#

# Clean up
input_fifo.destroy()
output_fifo.destroy()
graph.destroy()
device.close()
device.destroy()