Hello NV12 Input Classification Sample — OpenVINO™ documentation (original) (raw)
This sample demonstrates how to execute an inference of image classification models with images in NV12 color format using Synchronous Inference Request API. Before using the sample, refer to the following requirements:
- The sample accepts any file format supported by
ov::Core::read_model. - To build the sample, use instructions available at Build the Sample Applicationssection in “Get Started with Samples” guide.
How It Works#
At startup, the sample application reads command line parameters, loads the specified model and an image in the NV12 color format to an OpenVINO™ Runtime plugin. Then, the sample creates an synchronous inference request object. When inference is done, the application outputs data to the 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 atIntegration Stepssection of “Integrate OpenVINO™ Runtime with Your Application” guide.
Running#
C++
hello_nv12_input_classification
C
hello_nv12_input_classification_c
To run the sample, you need to specify a model and an image:
- You can get a model specific for your inference task from one of model repositories, such as TensorFlow Zoo, HuggingFace, or TensorFlow Hub.
- You can use images from the media files collection available atthe storage.
The sample accepts an uncompressed image in the NV12 color format. To run the sample, you need to convert your BGR/RGB image to NV12. To do this, you can use one of the widely available tools such as FFmpeg or GStreamer. Using FFmpeg and the following command, you can convert an ordinary image to an uncompressed NV12 image:
ffmpeg -i cat.jpg -pix_fmt nv12 cat.yuv
Note
- Because the sample reads raw image files, you should provide a correct image size along with the image path. The sample expects the logical size of the image, not the buffer size. For example, for 640x480 BGR/RGB image the corresponding NV12 logical image size is also 640x480, whereas the buffer size is 640x720.
- By default, this sample expects that model input has BGR channels order. If you trained your model to work with RGB order, you need to reconvert your model using model conversion API with
reverse_input_channelsargument specified. For more information about the argument, refer to theColor Conversion section of Preprocessing API. - Before running the sample with a trained model, make sure the model is converted to the intermediate representation (IR) format (*.xml + *.bin) using the model conversion API.
- The sample accepts models in ONNX format (.onnx) that do not require preprocessing.
Example#
- Download a pre-trained model.
- You can convert it by using:
- Perform inference of an NV12 image, using a model on a
CPU, for example:
C++
hello_nv12_input_classification ./models/alexnet.xml ./images/cat.yuv 300x300 CPU
C
hello_nv12_input_classification_c ./models/alexnet.xml ./images/cat.yuv 300x300 CPU
Sample Output#
C++
The application outputs top-10 inference results.
[ INFO ] OpenVINO Runtime version ......... [ INFO ] Build ........... [ INFO ] [ INFO ] Loading model files: \models\alexnet.xml [ INFO ] model name: AlexNet [ INFO ] inputs [ INFO ] input name: data [ INFO ] input type: f32 [ INFO ] input shape: {1, 3, 227, 227} [ INFO ] outputs [ INFO ] output name: prob [ INFO ] output type: f32 [ INFO ] output shape: {1, 1000}
Top 10 results:
Image \images\car.yuv
classid probability
656 0.6668988 654 0.1125269 581 0.0679280 874 0.0340229 436 0.0257744 817 0.0169367 675 0.0110199 511 0.0106134 569 0.0083373 717 0.0061734
C
The application outputs top-10 inference results.
Top 10 results:
Image ./cat.yuv
classid probability
435 0.091733 876 0.081725 999 0.069305 587 0.043726 666 0.038957 419 0.032892 285 0.030309 700 0.029941 696 0.021628 855 0.020339
This sample is an API example, for any performance measurements please use the dedicated benchmark_app tool