nGraph Function Creation C++ Sample

This sample demonstrates how to execute an synchronous inference using nGraph function feature to create a network, which uses weights from LeNet classification network, which is known to work well on digit classification tasks.

The sample supports only single-channel ubyte images as an input.

You do not need an XML file to create a network. The API of ngraph::Function allows to create a network on the fly from the source code.

nGraph Function Creation C++ Sample demonstrates the following Inference Engine API in your applications:

Feature API Description
Inference Engine Version InferenceEngine::GetInferenceEngineVersion Get Inference Engine API version
Available Devices InferenceEngine::Core::GetAvailableDevices Get version information of the devices for inference
Network Operations InferenceEngine::CNNNetwork::setBatchSize, InferenceEngine::CNNNetwork::getBatchSize Managing of network, operate with its batch size. Setting batch size using input image count.
nGraph Functions ngraph::Function, ngraph::op, ngraph::Node, ngraph::Shape::Shape, ngraph::Strides::Strides, ngraph::CoordinateDiff::CoordinateDiff, ngraph::Node::set_friendly_name, ngraph::shape_size, ngraph::ParameterVector::vector Illustrates how to construct an nGraph function

Basic Inference Engine API is covered by Hello Classification C++ sample.

Options Values
Validated Models LeNet
Model Format Network weights file (*.bin)
Validated images single-channel ubyte images
Supported devices All
Other language realization Python

How It Works

At startup, the sample application reads command-line parameters, prepares input data, creates a network using the nGraph function feature and passed weights file, loads the network and image(s) to the Inference Engine plugin, performs synchronous inference and processes output data, logging each step in a standard output stream. You can place labels in .labels file near the model to get pretty output.

You can see the explicit description of each sample step at Integration Steps section of "Integrate the Inference Engine with Your Application" guide.

Building

To build the sample, please use instructions available at Build the Sample Applications section in Inference Engine Samples guide.

Running

To run the sample, you need specify a model wights and ubyte image:

NOTES:

  • The lenet.bin with FP32 weights file was generated by the Model Optimizer tool from the public LeNet model with the --input_shape [64,1,28,28] parameter specified.

The original model is available in the Caffe* repository on GitHub*.

Running the application with the -h option yields the following usage message:

ngraph_function_creation_sample -h
[ INFO ] InferenceEngine:
API version ............<version>
Build ..................<build>
Description ....... API
[ INFO ] Parsing input parameters
ngraph_function_creation_sample [OPTION]
Options:
-h Print a usage message.
-m "<path>" Required. Path to a .bin file with weights for the trained model.
-i "<path>" Required. Path to a folder with images or path to image files. Support ubyte files only.
-d "<device>" Optional. Specify the target device to infer on (the list of available devices is shown below). Default value is CPU. Use "-d HETERO:<comma_separated_devices_list>" format to specify HETERO plugin. Sample will look for a suitable plugin for device specified.
-nt "<integer>" Number of top results. The default value is 10.
Available target devices: <devices>

Running the application with the empty list of options yields the usage message given above and an error message.

You can do inference of an image using a pre-trained model on a GPU using the following command:

<path_to_sample>/ngraph_function_creation_sample -m <path_to_weights_file>/lenet.bin -i <path_to_image> -d GPU

Sample Output

The sample application logs each step in a standard output stream and outputs top-10 inference results.

ngraph_function_creation_sample.exe -m lenet.bin -i 7-ubyte
[ INFO ] InferenceEngine:
API version ............ <version>
Build .................. <build>
Description ....... API
[ INFO ] Parsing input parameters
[ INFO ] Files were added: 1
[ INFO ] 7-ubyte
[ INFO ] Loading Inference Engine
[ INFO ] Device info:
CPU
MKLDNNPlugin version ......... <version>
Build ........... <build>
[ INFO ] Preparing input blobs
[ INFO ] Batch size is 1
[ INFO ] Checking that the outputs are as the sample expects
[ INFO ] Loading model to the device
[ INFO ] Create infer request
[ INFO ] Start inference
[ INFO ] Processing output blobs
Top 10 results:
Image 7-ubyte
classid probability
------- -----------
7 1.0000000
4 0.0000000
8 0.0000000
9 0.0000000
5 0.0000000
3 0.0000000
1 0.0000000
0 0.0000000
2 0.0000000
6 0.0000000
[ INFO ] This sample is an API example, for performance measurements, use the dedicated benchmark_app tool

Deprecation Notice

Deprecation Begins June 1, 2020
Removal Date December 1, 2020

Starting with the OpenVINO™ toolkit 2020.2 release, all of the features previously available through nGraph have been merged into the OpenVINO™ toolkit. As a result, all the features previously available through ONNX RT Execution Provider for nGraph have been merged with ONNX RT Execution Provider for OpenVINO™ toolkit.

Therefore, ONNX RT Execution Provider for nGraph will be deprecated starting June 1, 2020 and will be completely removed on December 1, 2020. Users are recommended to migrate to the ONNX RT Execution Provider for OpenVINO™ toolkit as the unified solution for all AI inferencing on Intel® hardware.

See Also