Graph.allocate()

Info Value
Package mvnc
Module mvncapi
Version 2.0
See also Device, Graph

Overview

This method allocates the Graph to a Device. 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.

Graph.destroy() frees the memory allocated with this method.

Syntax

graph.allocate(device, graph_buffer)

Parameters

Parameter Type 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 NCSDK mvNCCompile tool.

Return

None

Raises

Exception with a Status.INVALID_PARAMETERS code if an invalid option is passed or Exception with another status code from Status if underlying function calls return a status other than Status.OK.

Notes

None.

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
graph.allocate(device, graph_buffer)

#
# Use the device...
#

# Deallocate and destroy the graph handle, close the device, and destroy the device handle
graph.destroy()
device.close()
device.destroy()