Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / ie_bridges / python / sample / classification_sample / README.md
1 # Image Classification Python* Sample
2
3 This topic demonstrates how to run the Image Classification sample application, which performs
4 inference using image classification networks such as AlexNet and GoogLeNet.
5
6 ### How It Works
7
8 Upon the start-up, the sample application reads command line parameters and loads a network and an image to the Inference
9 Engine plugin. When inference is done, the application creates an
10 output image and outputs data to the standard output stream.
11
12 > **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).
13
14 ## Running
15
16 Run the application with the `-h` option yields the usage message:
17 ```
18 python3 classification_sample.py -h
19 ```
20 The command yields the following usage message:
21 ```
22 usage: classification_sample.py [-h] -m MODEL -i INPUT [INPUT ...]
23                                 [-l CPU_EXTENSION] [-pp PLUGIN_DIR]
24                                 [-d DEVICE] [--labels LABELS] [-nt NUMBER_TOP]
25                                 [-ni NUMBER_ITER] [-pc]
26
27 Options:
28   -h, --help            Show this help message and exit.
29   -m MODEL, --model MODEL
30                         Required. Path to an .xml file with a trained model.
31   -i INPUT [INPUT ...], --input INPUT [INPUT ...]
32                         Required. Path to a folder with images or path to an
33                         image files
34   -l CPU_EXTENSION, --cpu_extension CPU_EXTENSION
35                         Optional. Required for CPU custom layers. MKLDNN (CPU)-targeted custom layers.
36                         Absolute path to a shared library with the kernels
37                         implementations.
38   -pp PLUGIN_DIR, --plugin_dir PLUGIN_DIR
39                         Optional. Path to a plugin folder
40   -d DEVICE, --device DEVICE
41                         Optional. Specify the target device to infer on; CPU,
42                         GPU, FPGA, HDDL or MYRIAD is acceptable. The sample
43                         will look for a suitable plugin for device specified.
44                         Default value is CPU
45   --labels LABELS       Optional. Path to a labels mapping file
46   -nt NUMBER_TOP, --number_top NUMBER_TOP
47                         Optional. Number of top results
48   -ni NUMBER_ITER, --number_iter NUMBER_ITER
49                         Optional. Number of inference iterations
50   -pc, --perf_counts    Optional. Report performance counters
51 ```
52
53 Running the application with the empty list of options yields the usage message given above.
54
55 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/).
56
57 > **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).
58
59 For example, to perform inference of an AlexNet model (previously converted to the Inference Engine format) on CPU, use the following command:
60
61 ```
62     python3 classification_sample.py -i <path_to_image>/cat.bmp -m <path_to_model>/alexnet_fp32.xml
63 ```
64
65 ### Sample Output
66
67 By default the application outputs top-10 inference results.
68 Add the `-nt` option to the previous command to modify the number of top output results.
69 For example, to get the top-5 results on GPU, run the following command:
70 ```
71     python3 classification_sample.py<path_to_image>/cat.bmp -m <path_to_model>/alexnet_fp32.xml -nt 5 -d GPU
72 ```
73
74 ## See Also
75 * [Using Inference Engine Samples](./docs/IE_DG/Samples_Overview.md)
76 * [Model Optimizer tool](./docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md)
77 * [Model Downloader](https://github.com/opencv/open_model_zoo/tree/2018/model_downloader)
78
79