1 # Image Classification Python* Sample Async
3 This sample demonstrates how to build and execute inference in pipelined mode on example of classifications networks.
5 The pipelined mode might increase the throughput of the pictures. The latency of one inference will be the same as for synchronous execution.
7 The throughput increases due to follow reasons:
8 * Some plugins have heterogeneity inside themselves: data transferring, execution on remote device, pre-processing and post-processing on the host.
9 * Using of explicit heterogeneous plugin with execution of different parts of network on different devices, for example HETERO:CPU,GPU.
11 When two or more devices process one image, creating several infer requests and starting asynchronous inference allow for using devices in the most efficient way.
12 If two devices are involved in execution, the most optimal value for `-nireq` option is 2.
13 To process infer requests more efficiently, Classification Sample Async uses round-robin algorithm. It starts execution of the current infer request and switches to waiting for results of the previous one. After finishing of waiting, it switches infer requests and repeat the procedure.
15 Another required aspect of good throughput is a number of iterations. Only with big number of iterations you can emulate the real application work and get good performance.
17 The batch mode is an independent attribute on the pipelined mode. Pipelined mode works efficiently with any batch size.
21 Upon the start-up, the sample application reads command line parameters and loads a network and an image to the Inference
23 Then application creates several infer requests pointed in `-nireq` parameter and loads images for inference.
25 Then in a loop it starts inference for the current infer request and switches to waiting for the previous one. When results are ready, it swaps infer requests.
27 When inference is done, the application outputs data to the standard output stream.
29 > **NOTE**: By default, Inference Engine samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using the Model Optimizer tool with `--reverse_input_channels` argument specified. For more information about the argument, refer to **When to Specify Input Shapes** section of [Converting a Model Using General Conversion Parameters](./docs/MO_DG/prepare_model/convert_model/Converting_Model_General.md).
33 Running the application with the <code>-h</code> option yields the following usage message:
35 python3 classification_sample_async.py -h
37 The command yields the following usage message:
39 usage: classification_sample_async.py [-h] -m MODEL -i INPUT [INPUT ...]
40 [-l CPU_EXTENSION] [-pp PLUGIN_DIR]
41 [-d DEVICE] [--labels LABELS]
42 [-nt NUMBER_TOP] [-ni NUMBER_ITER] [-pc]
45 -h, --help Show this help message and exit.
46 -m MODEL, --model MODEL
47 Required. Path to an .xml file with a trained model.
48 -i INPUT [INPUT ...], --input INPUT [INPUT ...]
49 Required. Path to a folder with images or path to an
51 -l CPU_EXTENSION, --cpu_extension CPU_EXTENSION
52 Optional. Required for CPU custom layers. Absolute
53 path to a shared library with the kernels
55 -pp PLUGIN_DIR, --plugin_dir PLUGIN_DIR
56 Optional. Path to a plugin folder
57 -d DEVICE, --device DEVICE
58 Optional. Specify the target device to infer on; CPU,
59 GPU, FPGA, HDDL or MYRIAD is acceptable. The sample
60 will look for a suitable plugin for device specified.
62 --labels LABELS Optional. Labels mapping file
63 -nt NUMBER_TOP, --number_top NUMBER_TOP
64 Optional. Number of top results
65 -ni NUMBER_ITER, --number_iter NUMBER_ITER
66 Optional. Number of inference iterations
67 -pc, --perf_counts Optional. Report performance counters
71 Running the application with the empty list of options yields the usage message given above and an error message.
73 To run the sample, you can use AlexNet and GoogLeNet or other image classification models. You can download the pre-trained models with the OpenVINO [Model Downloader](https://github.com/opencv/open_model_zoo/tree/2018/model_downloader) or from [https://download.01.org/opencv/](https://download.01.org/opencv/).
75 > **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](./docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md).
78 You can do inference on an image using a trained AlexNet network on FPGA with fallback to CPU using the following command:
80 python3 classification_sample_async.py -i <path_to_image>/cat.bmp -m <path_to_model>/alexnet_fp32.xml -nt 5 -d HETERO:FPGA,CPU -nireq 2 -ni 200
85 By default, the application outputs top-10 inference results for each infer request.
86 It also provides throughput value measured in frames per seconds.
89 * [Using Inference Engine Samples](./docs/IE_DG/Samples_Overview.md)