---
# System prepended metadata

title: Use POT to Quantize SSD Moilent V1 Public Model
tags: [POT]

---

# Use POT to Quantize SSD Moilent V1 Public Model

###### tags: `POT`

## Use OpenVINO dockerhub image
```
docker run -it -v ~/Downloads:/mnt --rm openvino/ubuntu20_data_dev:latest
```


## Run Accuracy Checker and POT
In ubuntu20_data_dev docker image,

#### 1. Download ssd_mobilenet_v1_coco
python3 /opt/intel/openvino_2021.3.394/deployment_tools/tools/model_downloader/downloader.py -o /home/openvino/openvino_models --name ssd_mobilenet_v1_coco

#### 2. Convert ssd_mobilenet_v1_coco to IR
python3 /opt/intel/openvino_2021.3.394/deployment_tools/tools/model_downloader/converter.py -d /home/openvino/openvino_models -o /home/openvino/openvino_models --name ssd_mobilenet_v1_coco

#### 3. Run Accuracy Checker on ssd_mobilenet_v1_coco
accuracy_check -c ssd_mobilenet_v1_coco-int8.yml -m openvino_models/public/ssd_mobilenet_v1_coco/FP16/

#### 4. Run POT on ssd_mobilenet_v1_coco
rm mscoco_det_91.* 

pot -c ssd_mobilenet_v1_coco-int8.json

#### 5. Copy ssd_mobilenet_v1_coco FP16-INT8 IR

mkdir /home/openvino/openvino_models/public/ssd_mobilenet_v1_coco/FP16-INT8/
cp -ar results/ssd_mobilenet_v1_coco_DefaultQuantization/2021-04-20_00-02-37/optimized/* /home/openvino/openvino_models/public/ssd_mobilenet_v1_coco/FP16-INT8/

## Reference

```
drwxrwxrwx 1 openvino openvino    4096 May 24 03:32 coco_dataset
-rw-r--r-- 1 openvino openvino    1389 May 24 03:57 mscoco_det_91.json
-rw-r--r-- 1 openvino openvino 4048482 May 24 03:57 mscoco_det_91.pickle
drwxr-xr-x 3 openvino openvino    4096 May 24 03:26 openvino_models
drwxr-xr-x 3 openvino openvino    4096 May 24 03:49 results
-rw-r--r-- 1 openvino openvino     656 May 24 03:44 ssd_mobilenet_v1_coco-int8.json
-rw-r--r-- 1 openvino openvino     763 May 24 03:38 ssd_mobilenet_v1_coco-int8.yml
```

Note : Copy openvino_models foler to /mnt folder. They will be accessable in ~/Downloads folder in the host  and /mnt in the container.

### ssd_mobilenet_v1_coco-int8.yml
```
models:
  - name:  ssd_mobilenet_v1_coco
    launchers:
      - framework: dlsdk
        device: CPU
        adapter: ssd

    datasets:
      - name: ms_coco_detection_91_classes
        annotation_conversion:
          converter: mscoco_detection
          annotation_file: /home/openvino/coco_dataset/annotations/instances_val2017.json
          has_background: True
          sort_annotations: True
          use_full_label_map: True
        annotation: mscoco_det_91.pickle
        dataset_meta: mscoco_det_91.json
        data_source: /home/openvino/coco_dataset/val2017
        preprocessing:
          - type: resize
            size: 300
        postprocessing:
          - type: resize_prediction_boxes
        metrics:
          - type: coco_precision
```

### ssd_mobilenet_v1_coco-int8.json
```
{
    "model": {
        "model_name": "ssd_mobilenet_v1_coco",
        "model": "/home/openvino/openvino_models/public/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.xml",
        "weights": "/home/openvino/openvino_models/public/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.bin"
    },
    "engine": {
        "config": "/home/openvino/ssd_mobilenet_v1_coco-int8.yml"
    },
    "compression": {
        "algorithms": [
            {
                "name": "DefaultQuantization",
                "params": {
                    "preset": "performance",
                    "stat_subset_size": 100
                }
            }
        ]
    }
}
```

### accuracy_checker log
```
accuracy_check -c /mnt/ssd_mobilenet_v1_coco-int8.yml -m /home/openvino/openvino_models/public/ssd_mobilenet_v1_coco/FP16/
Processing info:
model: ssd_mobilenet_v1_coco
launcher: dlsdk
device: CPU
dataset: ms_coco_detection_91_classes
OpenCV version: 4.5.2-openvino
Annotation conversion for ms_coco_detection_91_classes dataset has been started
Parameters to be used for conversion:
converter: mscoco_detection
annotation_file: /home/openvino/coco_dataset/annotations/instances_val2017.json
has_background: True
sort_annotations: True
use_full_label_map: True
Total annotations size: 5000
100 / 5000 processed in 0.502s
200 / 5000 processed in 0.456s
300 / 5000 processed in 0.443s
400 / 5000 processed in 0.436s
500 / 5000 processed in 0.433s
600 / 5000 processed in 0.432s
700 / 5000 processed in 0.429s
800 / 5000 processed in 0.428s
900 / 5000 processed in 0.428s
1000 / 5000 processed in 0.429s
1100 / 5000 processed in 0.433s
1200 / 5000 processed in 0.438s
1300 / 5000 processed in 0.467s
1400 / 5000 processed in 0.466s
1500 / 5000 processed in 0.453s
1600 / 5000 processed in 0.448s
1700 / 5000 processed in 0.445s
1800 / 5000 processed in 0.442s
1900 / 5000 processed in 0.440s
2000 / 5000 processed in 0.438s
2100 / 5000 processed in 0.442s
2200 / 5000 processed in 0.438s
2300 / 5000 processed in 0.439s
2400 / 5000 processed in 0.439s
2500 / 5000 processed in 0.437s
2600 / 5000 processed in 0.437s
2700 / 5000 processed in 0.437s
2800 / 5000 processed in 0.438s
2900 / 5000 processed in 0.434s
3000 / 5000 processed in 0.439s
3100 / 5000 processed in 0.433s
3200 / 5000 processed in 0.434s
3300 / 5000 processed in 0.435s
3400 / 5000 processed in 0.429s
3500 / 5000 processed in 0.429s
3600 / 5000 processed in 0.427s
3700 / 5000 processed in 0.426s
3800 / 5000 processed in 0.424s
3900 / 5000 processed in 0.434s
4000 / 5000 processed in 0.428s
4100 / 5000 processed in 0.422s
4200 / 5000 processed in 0.428s
4300 / 5000 processed in 0.418s
4400 / 5000 processed in 0.418s
4500 / 5000 processed in 0.420s
4600 / 5000 processed in 0.415s
4700 / 5000 processed in 0.411s
4800 / 5000 processed in 0.408s
4900 / 5000 processed in 0.407s
5000 / 5000 processed in 0.405s
5000 objects processed in 21.717 seconds
Annotation conversion for ms_coco_detection_91_classes dataset has been finished
ms_coco_detection_91_classes dataset metadata will be saved to mscoco_det_91.json
Converted annotation for ms_coco_detection_91_classes dataset will be saved to mscoco_det_91.pickle
IE version: 2.1.2021.3.0-2787-60059f2c755-releases/2021/3
Loaded CPU plugin version:
    CPU - MKLDNNPlugin: 2.1.2021.3.0-2787-60059f2c755-releases/2021/3
Found model /home/openvino/openvino_models/public/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.xml
Found weights /home/openvino/openvino_models/public/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.bin
Input info:
        Layer name: image_tensor
        precision: FP32
        shape [1, 3, 300, 300]

Output info
        Layer name: DetectionOutput
        precision: FP32
        shape: [1, 1, 100, 7]

5000 objects processed in 126.727 seconds
coco_precision: 23.32%
```

### pot log

```
pot -c ssd_mobilenet_v1_coco-int8.json -e
INFO:app.run:Output log dir: ./results/ssd_mobilenet_v1_coco_DefaultQuantization/2021-05-24_03-49-38
INFO:app.run:Creating pipeline:
 Algorithm: DefaultQuantization
 Parameters:
        preset                     : performance
        stat_subset_size           : 100
        target_device              : ANY
        model_type                 : None
        dump_intermediate_model    : False
        exec_log_dir               : ./results/ssd_mobilenet_v1_coco_DefaultQuantization/2021-05-24_03-49-38
 ===========================================================================
IE version: 2.1.2021.3.0-2787-60059f2c755-releases/2021/3
Loaded CPU plugin version:
    CPU - MKLDNNPlugin: 2.1.2021.3.0-2787-60059f2c755-releases/2021/3
Annotation conversion for ms_coco_detection_91_classes dataset has been started
Parameters to be used for conversion:
converter: mscoco_detection
annotation_file: /home/openvino/coco_dataset/annotations/instances_val2017.json
has_background: True
sort_annotations: True
use_full_label_map: True
Total annotations size: 5000
100 / 5000 processed in 0.526s
200 / 5000 processed in 0.479s
300 / 5000 processed in 0.464s
400 / 5000 processed in 0.455s
500 / 5000 processed in 0.456s
600 / 5000 processed in 0.452s
700 / 5000 processed in 0.448s
800 / 5000 processed in 0.446s
900 / 5000 processed in 0.446s
1000 / 5000 processed in 0.446s
1100 / 5000 processed in 0.445s
1200 / 5000 processed in 0.444s
1300 / 5000 processed in 0.446s
1400 / 5000 processed in 0.446s
1500 / 5000 processed in 0.447s
1600 / 5000 processed in 0.448s
1700 / 5000 processed in 0.447s
1800 / 5000 processed in 0.448s
1900 / 5000 processed in 0.448s
2000 / 5000 processed in 0.451s
2100 / 5000 processed in 0.450s
2200 / 5000 processed in 0.450s
2300 / 5000 processed in 0.449s
2400 / 5000 processed in 0.449s
2500 / 5000 processed in 0.459s
2600 / 5000 processed in 0.455s
2700 / 5000 processed in 0.453s
2800 / 5000 processed in 0.449s
2900 / 5000 processed in 0.451s
3000 / 5000 processed in 0.449s
3100 / 5000 processed in 0.446s
3200 / 5000 processed in 0.452s
3300 / 5000 processed in 0.447s
3400 / 5000 processed in 0.445s
3500 / 5000 processed in 0.443s
3600 / 5000 processed in 0.441s
3700 / 5000 processed in 0.439s
3800 / 5000 processed in 0.441s
3900 / 5000 processed in 0.437s
4000 / 5000 processed in 0.435s
4100 / 5000 processed in 0.438s
4200 / 5000 processed in 0.430s
4300 / 5000 processed in 0.429s
4400 / 5000 processed in 0.427s
4500 / 5000 processed in 0.485s
4600 / 5000 processed in 0.490s
4700 / 5000 processed in 0.470s
4800 / 5000 processed in 0.458s
4900 / 5000 processed in 0.450s
5000 / 5000 processed in 0.481s
5000 objects processed in 22.584 seconds
Annotation conversion for ms_coco_detection_91_classes dataset has been finished
ms_coco_detection_91_classes dataset metadata will be saved to mscoco_det_91.json
Converted annotation for ms_coco_detection_91_classes dataset will be saved to mscoco_det_91.pickle
INFO:compression.statistics.collector:Start computing statistics for algorithms : DefaultQuantization
INFO:compression.statistics.collector:Computing statistics finished
INFO:compression.pipeline.pipeline:Start algorithm: DefaultQuantization
INFO:compression.algorithms.quantization.default.algorithm:Start computing statistics for algorithm : ActivationChannelAlignment
INFO:compression.algorithms.quantization.default.algorithm:Computing statistics finished
INFO:compression.algorithms.quantization.default.algorithm:Start computing statistics for algorithms : MinMaxQuantization,FastBiasCorrection
03:50:10 accuracy_checker WARNING: /opt/intel/openvino/deployment_tools/model_optimizer/mo/back/ie_ir_ver_2/emitter.py:243: DeprecationWarning: This method will be removed in future versions.  Use 'list(elem)' or iteration over elem instead.
  if len(element.attrib) == 0 and len(element.getchildren()) == 0:

INFO:compression.algorithms.quantization.default.algorithm:Computing statistics finished
INFO:compression.pipeline.pipeline:Finished: DefaultQuantization
 ===========================================================================
INFO:compression.pipeline.pipeline:Evaluation of generated model
INFO:compression.engines.ac_engine:Start inference on the whole dataset
Total dataset size: 5000
1000 / 5000 processed in 22.659s
2000 / 5000 processed in 22.778s
3000 / 5000 processed in 22.536s
4000 / 5000 processed in 22.595s
5000 / 5000 processed in 22.549s
5000 objects processed in 113.117 seconds
INFO:compression.engines.ac_engine:Inference finished
INFO:app.run:coco_precision             : 0.20299275184313892

```