---
# System prepended metadata

title: 'EASE : Use POT to Quantize yolo-v3-tf Public Model'
tags: [EASE, POT]

---

# EASE : Use POT to Quantize yolo-v3-tf Public Model

###### tags: `POT` `EASE`

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


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

#### 0. Download COCO 2017 trainval dataset and annotation

```=bash
cd /home/openvino
apt update
apt install unzip

mkdir coco_dataset
cd coco_dataset
curl http://images.cocodataset.org/zips/val2017.zip -o val2017.zip
unzip val2017.zip

curl http://images.cocodataset.org/annotations/annotations_trainval2017.zip -o trainval_2017.zip
unzip trainval_2017.zip
```

##### coco_dataset content

```
coco_dataset/
|--annotations/
  |-- captions_train2017.json
  |-- captions_val2017.json
  |-- instances_train2017.json
  |-- instances_val2017.json
  |-- person_keypoints_train2017.json
  `-- person_keypoints_val2017.json
|-- val2017/
    |-- 000000042102.jpg
    |-- 000000060102.jpg
    |-- 000000245102.jpg
    ...
    `-- 000000364102.jpg
```

#### 1. Download yolo-v3-tf

```=bash
omz_downloader.py --name yolo-v3-tf -o /home/openvino/openvino_models
```

#### 2. Convert yolo-v3-tf to IR

```=bash
omz_converter.py --name yolo-v3-tf -d /home/openvino/openvino_models -o /home/openvino/openvino_models
```

#### 3. Run Accuracy Checker on yolo-v3-tf

```=bash
accuracy_check -c yolo-v3-tf-int8.yml -m /home/openvino/openvino_models/public/yolo-v3-tf/FP32
```

#### 4. Run POT on yolo-v3-tf

```=bash
pot -c yolo-v3-tf-int8.json -e
```

#### 5. Copy yolo-v3-tf FP16-INT8 IR

```=bash
mkdir /home/openvino/openvino_models/public/yolo-v3-tf/FP16-INT8/
cp -ar results/yolo-v3-tf_DefaultQuantization/2*/optimized/* /home/openvino/openvino_models/public/yolo-v3-tf/FP16-INT8/

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

## Reference


### yolo-v3-tf-int8.yml
```
models:
  - name:  yolo_v3_tf
    launchers:
      - framework: dlsdk
        device: CPU
        adapter:
          type: yolo_v3
          anchors: "10,13,  16,30,  33,23,  30,61,  62,45,  59,119,  116,90,  156,198,  373,326"
          num: 9
          coords: 4
          classes: 80
          anchor_masks: [[6, 7, 8], [3, 4, 5], [0, 1, 2]]
          outputs:
            - conv2d_58/Conv2D/YoloRegion
            - conv2d_66/Conv2D/YoloRegion
            - conv2d_74/Conv2D/YoloRegion
    datasets:
      - name: ms_coco_detection_80_class_without_background
        annotation_conversion:
          converter: mscoco_detection
          annotation_file:  /home/openvino/coco_dataset/annotations/instances_val2017.json
        data_source: /home/openvino/coco_dataset/val2017
        preprocessing:
          - type: resize
            size: 416

        postprocessing:
          - type: resize_prediction_boxes
          - type: filter
            apply_to: prediction
            min_confidence: 0.001
            remove_filtered: True
          - type: nms
            overlap: 0.5
          - type: clip_boxes
            apply_to: prediction

        metrics:
          - type: map
            integral: 11point
            ignore_difficult: true
            presenter: print_scalar
            reference: 0.6227
          - type: coco_precision
            max_detections: 100
            threshold: 0.5
            reference: 0.677
```

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

### accuracy_checker log
```
accuracy_check -c /mnt/yolo-v3-tf-int8.yml -m /mnt/openvino_models/public/yolo-v3-tf/FP32/yolo-v3-tf.xml 
Processing info:
model: yolo_v3_tf
launcher: openvino
device: CPU
dataset: ms_coco_detection_80_class_without_background
OpenCV version: 4.5.5
Annotation conversion for ms_coco_detection_80_class_without_background dataset has been started
Parameters to be used for conversion:
converter: mscoco_detection
annotation_file: /mnt/coco_dataset/annotations/instances_val2017.json
Total annotations size: 5000
100 / 5000 processed in 0.602s
200 / 5000 processed in 0.675s
300 / 5000 processed in 0.565s
400 / 5000 processed in 0.573s
500 / 5000 processed in 0.544s
600 / 5000 processed in 0.539s
700 / 5000 processed in 0.529s
800 / 5000 processed in 0.594s
900 / 5000 processed in 0.516s
1000 / 5000 processed in 0.580s
1100 / 5000 processed in 0.555s
1200 / 5000 processed in 0.508s
1300 / 5000 processed in 0.521s
1400 / 5000 processed in 0.564s
1500 / 5000 processed in 0.534s
1600 / 5000 processed in 0.520s
1700 / 5000 processed in 0.519s
1800 / 5000 processed in 0.530s
1900 / 5000 processed in 0.583s
2000 / 5000 processed in 0.568s
2100 / 5000 processed in 0.546s
2200 / 5000 processed in 0.531s
2300 / 5000 processed in 0.577s
2400 / 5000 processed in 0.561s
2500 / 5000 processed in 0.581s
2600 / 5000 processed in 0.568s
2700 / 5000 processed in 0.571s
2800 / 5000 processed in 0.563s
2900 / 5000 processed in 0.568s
3000 / 5000 processed in 0.563s
3100 / 5000 processed in 0.566s
3200 / 5000 processed in 0.561s
3300 / 5000 processed in 0.567s
3400 / 5000 processed in 0.560s
3500 / 5000 processed in 0.567s
3600 / 5000 processed in 0.560s
3700 / 5000 processed in 0.562s
3800 / 5000 processed in 0.553s
3900 / 5000 processed in 0.605s
4000 / 5000 processed in 0.549s
4100 / 5000 processed in 0.529s
4200 / 5000 processed in 0.527s
4300 / 5000 processed in 0.514s
4400 / 5000 processed in 0.531s
4500 / 5000 processed in 0.523s
4600 / 5000 processed in 0.541s
4700 / 5000 processed in 0.495s
4800 / 5000 processed in 0.494s
4900 / 5000 processed in 0.501s
5000 / 5000 processed in 0.492s
5000 objects processed in 27.544 seconds
Annotation conversion for ms_coco_detection_80_class_without_background dataset has been finished
IE version: 2022.1.0-7019-cdb9bec7210-releases/2022/1
Loaded CPU plugin version:
    CPU - openvino_intel_cpu_plugin: 2022.1.2022.1.0-7019-cdb9bec7210-releases/2022/1
Found model /mnt/openvino_models/public/yolo-v3-tf/FP32/yolo-v3-tf.xml
Found weights /mnt/openvino_models/public/yolo-v3-tf/FP32/yolo-v3-tf.bin
Input info:
	Node name: input_1
	Tensor names: input_1:0, input_1
	precision: f32
	shape: (1, 416, 416, 3)

Output info
	Node name: conv2d_58/Conv2D/YoloRegion/sink_port_0
	Tensor names: conv2d_58/Conv2D/YoloRegion:0, conv2d_58/Conv2D/YoloRegion
	precision: f32
	shape: (1, 255, 13, 13)

	Node name: conv2d_66/Conv2D/YoloRegion/sink_port_0
	Tensor names: conv2d_66/Conv2D/YoloRegion, conv2d_66/Conv2D/YoloRegion:0
	precision: f32
	shape: (1, 255, 26, 26)

	Node name: conv2d_74/Conv2D/YoloRegion/sink_port_0
	Tensor names: conv2d_74/Conv2D/YoloRegion:0, conv2d_74/Conv2D/YoloRegion
	precision: f32
	shape: (1, 255, 52, 52)

5000 objects processed in 1673.242 seconds                                                                                                                                                                 
map: 62.27%
coco_precision: 67.70%
```

### pot log
```
pot -c /mnt/yolo-v3-tf-int8.json -e
INFO:openvino.tools.pot.app.run:Output log dir: ./results/yolo-v3-tf_DefaultQuantization/2022-04-30_08-39-57
INFO:openvino.tools.pot.app.run:Creating pipeline:
 Algorithm: DefaultQuantization
 Parameters:
	preset                     : performance
	stat_subset_size           : 300
	target_device              : ANY
	model_type                 : None
	dump_intermediate_model    : False
	inplace_statistics         : True
	exec_log_dir               : ./results/yolo-v3-tf_DefaultQuantization/2022-04-30_08-39-57
 ===========================================================================
IE version: 2022.1.0-7019-cdb9bec7210-releases/2022/1
Loaded CPU plugin version:
    CPU - openvino_intel_cpu_plugin: 2022.1.2022.1.0-7019-cdb9bec7210-releases/2022/1
Annotation conversion for ms_coco_detection_80_class_without_background dataset has been started
Parameters to be used for conversion:
converter: mscoco_detection
annotation_file: /mnt/coco_dataset/annotations/instances_val2017.json
Total annotations size: 5000
100 / 5000 processed in 0.566s
200 / 5000 processed in 0.564s
300 / 5000 processed in 0.640s
400 / 5000 processed in 0.591s
500 / 5000 processed in 0.603s
600 / 5000 processed in 0.563s
700 / 5000 processed in 0.565s
800 / 5000 processed in 0.567s
900 / 5000 processed in 0.569s
1000 / 5000 processed in 0.571s
1100 / 5000 processed in 0.574s
1200 / 5000 processed in 0.570s
1300 / 5000 processed in 0.610s
1400 / 5000 processed in 0.588s
1500 / 5000 processed in 0.581s
1600 / 5000 processed in 0.577s
1700 / 5000 processed in 0.576s
1800 / 5000 processed in 0.587s
1900 / 5000 processed in 0.586s
2000 / 5000 processed in 0.579s
2100 / 5000 processed in 0.592s
2200 / 5000 processed in 0.626s
2300 / 5000 processed in 0.585s
2400 / 5000 processed in 0.584s
2500 / 5000 processed in 0.581s
2600 / 5000 processed in 0.580s
2700 / 5000 processed in 0.581s
2800 / 5000 processed in 0.579s
2900 / 5000 processed in 0.586s
3000 / 5000 processed in 0.622s
3100 / 5000 processed in 0.589s
3200 / 5000 processed in 0.576s
3300 / 5000 processed in 0.585s
3400 / 5000 processed in 0.574s
3500 / 5000 processed in 0.572s
3600 / 5000 processed in 0.570s
3700 / 5000 processed in 0.570s
3800 / 5000 processed in 0.578s
3900 / 5000 processed in 0.608s
4000 / 5000 processed in 0.568s
4100 / 5000 processed in 0.566s
4200 / 5000 processed in 0.564s
4300 / 5000 processed in 0.561s
4400 / 5000 processed in 0.560s
4500 / 5000 processed in 0.560s
4600 / 5000 processed in 0.558s
4700 / 5000 processed in 0.565s
4800 / 5000 processed in 0.594s
4900 / 5000 processed in 0.565s
5000 / 5000 processed in 0.554s
5000 objects processed in 28.983 seconds
Annotation conversion for ms_coco_detection_80_class_without_background dataset has been finished
INFO:openvino.tools.pot.pipeline.pipeline:Inference Engine version:                2022.1.0-7019-cdb9bec7210-releases/2022/1
INFO:openvino.tools.pot.pipeline.pipeline:Model Optimizer version:                 2022.1.0-7019-cdb9bec7210-releases/2022/1
INFO:openvino.tools.pot.pipeline.pipeline:Post-Training Optimization Tool version: 2022.1.0-7019-cdb9bec7210-releases/2022/1
INFO:openvino.tools.pot.statistics.collector:Start computing statistics for algorithms : DefaultQuantization
INFO:openvino.tools.pot.statistics.collector:Computing statistics finished
INFO:openvino.tools.pot.pipeline.pipeline:Start algorithm: DefaultQuantization
INFO:openvino.tools.pot.algorithms.quantization.default.algorithm:Start computing statistics for algorithm : ActivationChannelAlignment
INFO:openvino.tools.pot.algorithms.quantization.default.algorithm:Computing statistics finished
INFO:openvino.tools.pot.algorithms.quantization.default.algorithm:Start computing statistics for algorithms : MinMaxQuantization,FastBiasCorrection
INFO:openvino.tools.pot.algorithms.quantization.default.algorithm:Computing statistics finished
INFO:openvino.tools.pot.pipeline.pipeline:Finished: DefaultQuantization
 ===========================================================================
INFO:openvino.tools.pot.pipeline.pipeline:Evaluation of generated model
INFO:openvino.tools.pot.engines.ac_engine:Start inference on the whole dataset
Total dataset size: 5000
1000 / 5000 processed in 120.165s
2000 / 5000 processed in 124.478s
3000 / 5000 processed in 122.800s
4000 / 5000 processed in 123.251s
5000 / 5000 processed in 122.487s
5000 objects processed in 613.181 seconds
INFO:openvino.tools.pot.engines.ac_engine:Inference finished
INFO:openvino.tools.pot.app.run:map                        : 0.6196563903778992
INFO:openvino.tools.pot.app.run:coco_precision             : 0.6766990257494002
```