Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / samples / calibration_tool / README.md
1 # Calibration Tool
2
3 Inference Engine Calibration Tool calibrates a given FP32 model so that is can be run in low-precision 8-bit integer
4 mode while keeping the input data of this model in the original precision.
5
6 > **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).
7
8 ## Calibration Tool Options
9
10 The core command-line options for the Calibration Tool are the same as for
11 [Validation Application](./inference-engine/samples/validation_app/README.md). However, the Calibration Tool has the following specific options: `-t`, `-subset`, `-output`, and `-threshold`.
12
13 Running the Calibration Tool with the `-h` option yields the following usage message:
14 ```sh  
15 Usage: calibration_tool [OPTION]
16
17 Available options:
18
19     -h                        Print a help message
20     -t <type>                 Type of an inferred network ("C" by default)
21       -t "C" to calibrate Classification network and write the calibrated network to IR
22       -t "OD" to calibrate Object Detection network and write the calibrated network to IR
23       -t "RawC" to collect only statistics for Classification network and write statistics to IR. With this option, a model is not calibrated. For calibration and statisctics collection, use "-t C" instead.
24       -t "RawOD" to collect only statistics for Object Detection network and write statistics to IR. With this option, a model is not calibrated. For calibration and statisctics collection, use "-t OD" instead
25     -i <path>                 Required. Path to a directory with validation images. For Classification models, the directory must contain folders named as labels with images inside or a .txt file with a list of images. For Object Detection models, the dataset must be in VOC format.
26     -m <path>                 Required. Path to an .xml file with a trained model, including model name and extension.
27     -lbl <path>               Labels file path. The labels file contains names of the dataset classes
28     -l <absolute_path>        Required for CPU custom layers. Absolute path to a shared library with the kernel implementations.
29     -c <absolute_path>        Required for GPU custom kernels. Absolute path to an .xml file with the kernel descriptions.
30     -d <device>               Target device to infer on: CPU (default), GPU, FPGA, HDDL or MYRIAD. The application looks for a suitable plugin for the specified device.
31     -b N                      Batch size value. If not specified, the batch size value is taken from IR
32     -ppType <type>            Preprocessing type. Options: "None", "Resize", "ResizeCrop"
33     -ppSize N                 Preprocessing size (used with ppType="ResizeCrop")
34     -ppWidth W                Preprocessing width (overrides -ppSize, used with ppType="ResizeCrop")
35     -ppHeight H               Preprocessing height (overrides -ppSize, used with ppType="ResizeCrop")
36     --dump                    Dump file names and inference results to a .csv file
37     -subset                   Number of pictures from the whole validation set tocreate the calibration dataset. Default value is 0, which stands forthe whole provided dataset
38     -output <output_IR>       Output name for calibrated model. Default is <original_model_name>_i8.xml|bin
39     -threshold                Threshold for a maximum accuracy drop of quantized model. Must be an integer number (percents) without a percent sign. Default value is 1, which stands for accepted accuracy drop in 1%
40     -stream_output            Flag for printing progress as a plain text.When used, interactive progress bar is replaced with multiline output
41
42     Classification-specific options:
43       -Czb true               "Zero is a background" flag. Some networks are trained with a modified dataset where the class IDs  are enumerated from 1, but 0 is an undefined "background" class (which is never detected)
44
45     Object detection-specific options:
46       -ODkind <kind>          Type of an Object Detection model. Options: SSD
47       -ODa <path>             Required for Object Detection models. Path to a directory containing an .xml file with annotations for images.
48       -ODc <file>             Required for Object Detection models. Path to a file with a list of classes
49       -ODsubdir <name>        Directory between the path to images (specified with -i) and image name (specified in the .xml file). For VOC2007 dataset, use JPEGImages.
50 ```
51
52 The tool options are divided into two categories:
53 1. **Common options** named with a single letter or a word, such as <code>-b</code> or <code>--dump</code>.
54    These options are the same in all calibration tool modes.
55 2. **Network type-specific options** named as an acronym of the network type (<code>C</code> or <code>OD</code>)
56    followed by a letter or a word.
57
58 You can run the tool with public or pre-trained models. To download the pre-trained models, use the OpenVINO [Model Downloader](https://github.com/opencv/open_model_zoo/tree/2018/model_downloader) or go to [https://download.01.org/opencv/](https://download.01.org/opencv/).
59
60 > **NOTE**: Before running the tool on 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).
61
62 ## Calibrate a Classification Model
63
64 To calibrate a classification convolutional neural network (CNN)
65 on a subset of images (first 2000 images) from the given dataset (specified with the `-i` option), run the following command:
66
67 ```bash
68 ./calibration_tool -t C -i <path_to_images_directory_or_txt_file> -m <path_to_classification_model>/<model_name>.xml -d <CPU|GPU> -subset 2000
69 ```
70
71 The dataset must have the correct format. Classification models support two formats: folders
72 named as labels that contain all images of this class and ImageNet*-like format, with the
73 `.txt` file containing list of images and IDs of classes.
74
75 For more information on the structure of the datasets, refer to the **Prepare a Dataset** section of the
76 [Validation Application document](./inference-engine/samples/validation_app/README.md).
77
78 If you decide to use the subset of the given dataset, use the ImageNet-like format
79 instead of "folder as classes" format. This brings a more accurate calibration as you are likely to get images
80 representing different classes.
81
82 To run the sample you can use classification models that can be downloaded with the OpenVINO [Model Downloader](https://github.com/opencv/open_model_zoo/tree/2018/model_downloader) or other image classification models.
83
84 For example, to calibrate the trained Caffe\* `resnet-50` classification model, run the following command:
85
86 ```bash
87 ./calibration_tool -t C -m <path_to_model>/resnet-50.xml -i ILSVRC2012_val.txt -Czb false -ppType "ResizeCrop" -ppSize 342 -b 1 -d CPU -subset 2000
88 ```
89
90 ## Calibrate Object Detection Model
91
92 This topic demonstrates how to run the Calibration Tool on the Object Detection CNN on a set of images. Please
93 review the list of Object Detection models used for validation of the Calibration Tool
94 in the [8-bit Inference Introduction](./docs/IE_DG/Int8Inference.md).
95 Any network that can be inferred with the Inference Engine and has the same input and output
96 format as the SSD CNN should be supported as well.
97
98 ### Run SSD Network on the VOC dataset
99
100 Before you start calibrating the model, make sure your dataset is in the correct format. For more information,
101 refer to the **Prepare a Dataset** section of the
102 [Validation Application document](./inference-engine/samples/validation_app/README.md).
103
104 Once you have prepared the dataset, you can calibrate the model on it by running the following command:
105 ```bash
106 ./calibration_tool -d CPU -t OD -ODa "<path_to_image_annotations>/VOCdevkit/VOC2007/Annotations" -i "<path_to_image_directory>/VOCdevkit" -m "<path_to_model>/vgg_voc0712_ssd_300x300.xml" -ODc "<path_to_classes_list>/VOC_SSD_Classes.txt" -ODsubdir JPEGImages -subset 500
107 ```
108
109 ## See Also
110
111 * [Using Inference Engine Samples](./docs/IE_DG/Samples_Overview.md)
112 * [Model Optimizer](./docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md)
113 * [Model Downloader](https://github.com/opencv/open_model_zoo/tree/2018/model_downloader)