Image classification with Squeezenet in CPP using OpenVINO Execution Provider:
-
The image classification uses a Squeezenet Deep Learning ONNX Model from the ONNX Model Zoo.
-
The sample involves presenting an image to the ONNX Runtime (RT), which uses the OpenVINO Execution Provider for ONNX RT to run inference on various Intel hardware devices like Intel CPU, GPU, VPU and more. The sample uses OpenCV for image processing and ONNX Runtime OpenVINO EP for inference. After the sample image is inferred, the terminal will output the predicted label classes in order of their confidence.
The source code for this sample is available here.
How to build
Prerequisites
-
Use opencv (use the same opencv package that comes builtin with Intel® Distribution of OpenVINO toolkit)
-
Use any sample image as input to the sample.
-
Download the latest Squeezenet model from the ONNX Model Zoo. This example was adapted from ONNX Model Zoo.Download the latest version of the Squeezenet model from here.
Install ONNX Runtime for OpenVINO Execution Provider
Build steps
Reference Documentation
If you build it by yourself, you must append the “–build_shared_lib” flag to your build command.
./build.sh --config Release --use_openvino CPU_FP32 --build_shared_lib
Build the sample C++ Application
-
Navigate to the directory /onnxruntime/build/Linux/Release/
-
Now copy all the files required to run this sample at this same location (/onnxruntime/build/Linux/Release/)
-
compile the sample
g++ -o run_squeezenet squeezenet_cpp_app.cpp -I ../../../include/onnxruntime/core/session/ -I /opt/intel/openvino_2021.3.394/opencv/include/ -I /opt/intel/openvino_2021.3.394/opencv/lib/ -L ./ -lonnxruntime_providers_openvino -lonnxruntime_providers_shared -lonnxruntime -L /opt/intel/openvino_2021.3.394/opencv/lib/ -lopencv_imgcodecs -lopencv_dnn -lopencv_core -lopencv_imgproc
Note: This build command is using the opencv location from OpenVINO 2021.3 Release Installation. You can use any version of OpenVINO and change the location path accordingly.
-
Run the sample
To Run
(using Intel OpenVINO-EP)
./run_squeezenet --use_openvino <path_to_onnx_model> <path_to_sample_image> <path_to_labels_file>
Example:
./run_squeezenet --use_openvino squeezenet1.1-7.onnx demo.jpeg synset.txt (using Intel OpenVINO-EP)
(using Default CPU)
./run_squeezenet --use_cpu <path_to_onnx_model> <path_to_sample_image> <path_to_labels_file>
Example:
./run_squeezenet --use_cpu squeezenet1.1-7.onnx demo.jpeg synset.txt (using Default CPU)