Files
openvino/inference-engine/samples/hello_nv12_input_classification
Rafik Saliev d225ba6e53 [IE] Add batched blob support (#2203)
* [IE] Add batched blob support

New `class BatchedBlob : public CompoundBlob` defined to allow to pass multiple blobs as 1 InferRequest input.

Motivation: There is the special user case when a number of plain images (e.g. `NV12Blob`) should be passed as one input for network which batch size > 1.

`class CompoundBlob` is not applicable for such cases due to:
1. `NV12Blob` is `CompoundBlob` which prevents to combine multiple NV12 images to a CompoundBlob
2. The default behavior in most of plugins - do not accept generic CompoundBlob as `SetBlob()` argument

Adding `SetBlob(name, vector<Blob::Ptr>...)` to `class IInferRequest`, `class InferRequest`, `class IInferRequestInternal`, ...  - is not effective solution due to limited and specific use cases for `batched inputs`.

+ Apply rule-of-zero to CompoundBlob and inherited classes.

* Add "BATCHED_BLOB" optimization capability metric

* Add BatchedBlob usage to hello_nv12_input_classification

* Apply offline code review outcome:

1. Revert CompoundBlob public .ctors signatures
2. Remove 'workaround' .ctor for `BatchedBlob`
3. Revert tensor descriptors of `I420Blob` `NV12Blob` back to the 'fake' value.

* Code review fix

* Add functional tests for CPU, GPU, MULTI, HETERO

* update doc comment

* Apply code review change requests.
2020-11-03 21:19:26 +03:00
..
2020-02-11 22:48:49 +03:00
2020-11-03 21:19:26 +03:00

Hello NV12 Input Classification C++ Sample

This topic describes how to run the Hello NV12 Input Classification sample application. The sample is a simplified version of the Image Classification Sample Async. It demonstrates how to use the new NV12 automatic input pre-processing API of the Inference Engine in your applications. Refer to Integrate the Inference Engine New Request API with Your Application for details.

How It Works

Upon the start-up, the sample application reads command-line parameters, loads a network and sets an image in the NV12 color format to an Inference Engine plugin. When inference is done, the application outputs data to the standard output stream.

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*. The following command shows how to convert an ordinary image into an uncompressed NV12 image using FFmpeg:

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.
  • The sample uses input autoresize API of the Inference Engine to simplify user-side pre-processing.
  • By default, this sample expects that network input has BGR channels order. If you trained your model to work with RGB order, you need to reconvert your model using the Model Optimizer tool with --reverse_input_channels argument specified. For more information about the argument, refer to When to Reverse Input Channels section of Converting a Model Using General Conversion Parameters.

Running

To run the sample, you can use public or pre-trained models. To download pre-trained models, use the OpenVINO™ [Model Downloader](@ref omz_tools_downloader_README) or go to https://download.01.org/opencv/.

Note

: Before running the sample with a trained model, make sure the model is converted to the Inference Engine format (*.xml + *.bin) using the Model Optimizer tool.

The sample accepts models in ONNX format (.onnx) that do not require preprocessing.

You can perform inference on an NV12 image using a trained AlexNet network on CPU with the following command:

./hello_nv12_input_classification <path_to_model>/alexnet_fp32.xml <path_to_image>/cat.yuv 640x480 CPU

Sample Output

The application outputs top-10 inference results.

See Also