|
| 1 | +# Classification Python\* Demo |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +This demo showcases inference of Classification networks using Python\* Model API and Async Pipeline. |
| 6 | + |
| 7 | +## How It Works |
| 8 | + |
| 9 | +On startup, the application reads command line parameters and loads a classification network to the Inference Engine for execution. Upon getting a frame from the OpenCV VideoCapture, it performs inference and displays the results. |
| 10 | + |
| 11 | +You can stop the demo by pressing "Esc" or "Q" button. After that, the average metrics values will be printed to the console. |
| 12 | + |
| 13 | +> **NOTE**: By default, Open Model Zoo 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 demo application or reconvert your model using the Model Optimizer tool with the `--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](https://docs.openvino.ai/latest/openvino_docs_MO_DG_prepare_model_convert_model_Converting_Model.html#general-conversion-parameters). |
| 14 | +
|
| 15 | +## Preparing to Run |
| 16 | + |
| 17 | +The list of models supported by the demo is in `<omz_dir>/demos/classification_demo/python/models.lst` file. |
| 18 | +This file can be used as a parameter for [Model Downloader](../../../tools/model_tools/README.md) and Converter to download and, if necessary, convert models to OpenVINO Inference Engine format (\*.xml + \*.bin). |
| 19 | + |
| 20 | +An example of using the Model Downloader: |
| 21 | + |
| 22 | +```sh |
| 23 | +omz_downloader --list models.lst |
| 24 | +``` |
| 25 | + |
| 26 | +An example of using the Model Converter: |
| 27 | + |
| 28 | +```sh |
| 29 | +omz_converter --list models.lst |
| 30 | +``` |
| 31 | + |
| 32 | +### Supported Models |
| 33 | + |
| 34 | +* alexnet |
| 35 | +* caffenet |
| 36 | +* densenet-121 |
| 37 | +* densenet-121-caffe2 |
| 38 | +* densenet-121-tf |
| 39 | +* densenet-161 |
| 40 | +* densenet-161-tf |
| 41 | +* densenet-169 |
| 42 | +* densenet-169-tf |
| 43 | +* densenet-201 |
| 44 | +* densenet-201-tf |
| 45 | +* dla-34 |
| 46 | +* efficientnet-b0 |
| 47 | +* efficientnet-b0_auto_aug |
| 48 | +* efficientnet-b0-pytorch |
| 49 | +* efficientnet-b5 |
| 50 | +* efficientnet-b5-pytorch |
| 51 | +* efficientnet-b7_auto_aug |
| 52 | +* efficientnet-b7-pytorch |
| 53 | +* googlenet-v1 |
| 54 | +* googlenet-v1-tf |
| 55 | +* googlenet-v2 |
| 56 | +* googlenet-v3 |
| 57 | +* googlenet-v3-pytorch |
| 58 | +* googlenet-v4-tf |
| 59 | +* hbonet-0.25 |
| 60 | +* hbonet-0.5 |
| 61 | +* hbonet-1.0 |
| 62 | +* inception-resnet-v2-tf |
| 63 | +* mixnet-l |
| 64 | +* mobilenet-v1-0.25-128 |
| 65 | +* mobilenet-v1-0.50-160 |
| 66 | +* mobilenet-v1-0.50-224 |
| 67 | +* mobilenet-v1-1.0-224 |
| 68 | +* mobilenet-v1-1.0-224-tf |
| 69 | +* mobilenet-v2 |
| 70 | +* mobilenet-v2-1.0-224 |
| 71 | +* mobilenet-v2-1.4-224 |
| 72 | +* mobilenet-v2-pytorch |
| 73 | +* nfnet-f0 |
| 74 | +* octave-densenet-121-0.125 |
| 75 | +* octave-resnet-101-0.125 |
| 76 | +* octave-resnet-200-0.125 |
| 77 | +* octave-resnet-26-0.25 |
| 78 | +* octave-resnet-50-0.125 |
| 79 | +* octave-resnext-101-0.25 |
| 80 | +* octave-resnext-50-0.25 |
| 81 | +* octave-se-resnet-50-0.125 |
| 82 | +* regnetx-3.2gf |
| 83 | +* repvgg-a0 |
| 84 | +* repvgg-b1 |
| 85 | +* repvgg-b3 |
| 86 | +* resnest-50-pytorch |
| 87 | +* resnet-18-pytorch |
| 88 | +* resnet-50-caffe2 |
| 89 | +* resnet-50-pytorch |
| 90 | +* resnet-50-tf |
| 91 | +* resnet18-xnor-binary-onnx-0001 |
| 92 | +* resnet50-binary-0001 |
| 93 | +* rexnet-v1-x1.0 |
| 94 | +* se-inception |
| 95 | +* se-resnet-101 |
| 96 | +* se-resnet-152 |
| 97 | +* se-resnet-50 |
| 98 | +* se-resnext-101 |
| 99 | +* se-resnext-50 |
| 100 | +* shufflenet-v2-x0.5 |
| 101 | +* shufflenet-v2-x1.0 |
| 102 | +* squeezenet1.0 |
| 103 | +* squeezenet1.1 |
| 104 | +* squeezenet1.1-caffe2 |
| 105 | +* swin-tiny-patch4-window7-224 |
| 106 | +* vgg16 |
| 107 | +* vgg19 |
| 108 | +* vgg19-caffe2 |
| 109 | + |
| 110 | +> **NOTE**: Refer to the tables [Intel's Pre-Trained Models Device Support](../../../models/intel/device_support.md) and [Public Pre-Trained Models Device Support](../../../models/public/device_support.md) for the details on models inference support at different devices. |
| 111 | +
|
| 112 | +### Required Files |
| 113 | + |
| 114 | +If you want to see classification results, you must use "-labels" flags to specify .txt file containing lists of classes and labels. |
| 115 | + |
| 116 | +Please note that you should use `<omz_dir>/data/dataset_classes/imagenet_2015.txt` labels file with the following models: |
| 117 | + |
| 118 | +* googlenet-v2 |
| 119 | +* se-inception |
| 120 | +* se-resnet-101 |
| 121 | +* se-resnet-152 |
| 122 | +* se-resnet-50 |
| 123 | +* se-resnext-101 |
| 124 | +* se-resnext-50 |
| 125 | + |
| 126 | +and `<omz_dir>/data/dataset_classes/imagenet_2012.txt` labels file with all other models supported by the demo. |
| 127 | + |
| 128 | +## Running |
| 129 | + |
| 130 | +Running the application with the `-h` option yields the following usage message: |
| 131 | + |
| 132 | +``` |
| 133 | +usage: classification_demo.py [-h] -m MODEL -i INPUT [-d DEVICE] --labels LABELS [-ntop {1,2,3,4,5,6,7,8,9,10}] |
| 134 | + [-nireq NUM_INFER_REQUESTS] [-nstreams NUM_STREAMS] [-nthreads NUM_THREADS] [--loop] |
| 135 | + [-o OUTPUT] [-limit OUTPUT_LIMIT] [--no_show] [--output_resolution OUTPUT_RESOLUTION] |
| 136 | + [-u UTILIZATION_MONITORS] [--reverse_input_channels] |
| 137 | + [--mean_values MEAN_VALUES MEAN_VALUES MEAN_VALUES] |
| 138 | + [--scale_values SCALE_VALUES SCALE_VALUES SCALE_VALUES] [-r] |
| 139 | +
|
| 140 | +Options: |
| 141 | + -h, --help Show this help message and exit. |
| 142 | + -m MODEL, --model MODEL |
| 143 | + Required. Path to an .xml file with a trained model. |
| 144 | + -i INPUT, --input INPUT |
| 145 | + Required. An input to process. The input must be a single image, a folder of images, video |
| 146 | + file or camera id. |
| 147 | + -d DEVICE, --device DEVICE |
| 148 | + Optional. Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD is acceptable. The |
| 149 | + demo will look for a suitable plugin for device specified. Default value is CPU. |
| 150 | +
|
| 151 | +Common model options: |
| 152 | + --labels LABELS Required. Labels mapping file. |
| 153 | + -ntop {1,2,3,4,5,6,7,8,9,10} |
| 154 | + Optional. Number of top results. Default value is 5. Must be from 1 to 10. |
| 155 | +
|
| 156 | +Inference options: |
| 157 | + -nireq NUM_INFER_REQUESTS, --num_infer_requests NUM_INFER_REQUESTS |
| 158 | + Optional. Number of infer requests |
| 159 | + -nstreams NUM_STREAMS, --num_streams NUM_STREAMS |
| 160 | + Optional. Number of streams to use for inference on the CPU or/and GPU in throughput mode (for |
| 161 | + HETERO and MULTI device cases use format <device1>:<nstreams1>,<device2>:<nstreams2> or just |
| 162 | + <nstreams>). |
| 163 | + -nthreads NUM_THREADS, --num_threads NUM_THREADS |
| 164 | + Optional. Number of threads to use for inference on CPU (including HETERO cases). |
| 165 | +
|
| 166 | +Input/output options: |
| 167 | + --loop Optional. Enable reading the input in a loop. |
| 168 | + -o OUTPUT, --output OUTPUT |
| 169 | + Optional. Name of the output file(s) to save. |
| 170 | + -limit OUTPUT_LIMIT, --output_limit OUTPUT_LIMIT |
| 171 | + Optional. Number of frames to store in output. If 0 is set, all frames are stored. |
| 172 | + --no_show Optional. Don't show output. |
| 173 | + --output_resolution OUTPUT_RESOLUTION |
| 174 | + Optional. Specify the maximum output window resolution in (width x height) format. Example: |
| 175 | + 1280x720. Input frame size used by default. |
| 176 | + -u UTILIZATION_MONITORS, --utilization_monitors UTILIZATION_MONITORS |
| 177 | + Optional. List of monitors to show initially. |
| 178 | +
|
| 179 | +Input transform options: |
| 180 | + --reverse_input_channels |
| 181 | + Optional. Switch the input channels order from BGR to RGB. |
| 182 | + --mean_values MEAN_VALUES MEAN_VALUES MEAN_VALUES |
| 183 | + Optional. Normalize input by subtracting the mean values per channel. Example: 255 255 255 |
| 184 | + --scale_values SCALE_VALUES SCALE_VALUES SCALE_VALUES |
| 185 | + Optional. Divide input by scale values per channel. Division is applied after mean values |
| 186 | + subtraction. Example: 255 255 255 |
| 187 | +
|
| 188 | +Debug options: |
| 189 | + -r, --raw_output_message |
| 190 | + Optional. Output inference results raw values showing. |
| 191 | +``` |
| 192 | + |
| 193 | +Running the application with the empty list of options yields an error message. |
| 194 | + |
| 195 | +For example, use the following command-line command to run the application: |
| 196 | + |
| 197 | +```sh |
| 198 | +python3 classification_demo.py -m <path_to_classification_model> \ |
| 199 | + -i <path_to_folder_with_images> \ |
| 200 | + --labels <path_to_file_with_list_of_labels> |
| 201 | +``` |
| 202 | + |
| 203 | +## Demo Output |
| 204 | + |
| 205 | +The demo uses OpenCV to display images with classification results presented as a text on them. The demo reports: |
| 206 | + |
| 207 | +* **FPS**: average rate of video frame processing (frames per second). |
| 208 | +* **Latency**: average time required to process one frame (from reading the frame to displaying the results). |
| 209 | +* Latency for each of the following pipeline stages: |
| 210 | + * **Decoding** — capturing input data. |
| 211 | + * **Preprocessing** — data preparation for inference. |
| 212 | + * **Inference** — infering input data (images) and getting a result. |
| 213 | + * **Postrocessing** — preparation inference result for output. |
| 214 | + * **Rendering** — generating output image. |
| 215 | + |
| 216 | +You can use these metrics to measure application-level performance. |
| 217 | + |
| 218 | +## See Also |
| 219 | + |
| 220 | +* [Open Model Zoo Demos](../../README.md) |
| 221 | +* [Model Optimizer](https://docs.openvinotoolkit.org/latest/_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html) |
| 222 | +* [Model Downloader](../../../tools/model_tools/README.md) |
0 commit comments