README.md 2.1 KB
Newer Older
Y
Yuantao Feng 已提交
1
# Quantization with ONNXRUNTIME and Neural Compressor
2

Y
Yuantao Feng 已提交
3
[ONNXRUNTIME](https://github.com/microsoft/onnxruntime) and [Neural Compressor](https://github.com/intel/neural-compressor) are used for quantization in the Zoo.
4 5 6 7 8 9 10 11 12 13

Install dependencies before trying quantization:
```shell
pip install -r requirements.txt
```

## Usage

Quantize all models in the Zoo:
```shell
14 15
python quantize-ort.py
python quantize-inc.py
16 17 18 19 20
```

Quantize one of the models in the Zoo:
```shell
# python quantize.py <key_in_models>
21 22
python quantize-ort.py yunet
python quantize-inc.py mobilenetv1
23 24 25 26
```

Customizing quantization configs:
```python
27 28
# Quantize with ONNXRUNTIME
# 1. add your model into `models` dict in quantize-ort.py
29 30
models = dict(
    # ...
31
    model1=Quantize(model_path='/path/to/model1.onnx',
32 33 34 35 36 37 38
                    calibration_image_dir='/path/to/images',
                    transforms=Compose([''' transforms ''']), # transforms can be found in transforms.py
                    per_channel=False, # set False to quantize in per-tensor style
                    act_type='int8',   # available types: 'int8', 'uint8'
                    wt_type='int8'     # available types: 'int8', 'uint8'
    )
)
39 40 41 42 43 44 45 46 47 48 49 50 51 52
# 2. quantize your model
python quantize-ort.py model1


# Quantize with Intel Neural Compressor
# 1. add your model into `models` dict in quantize-inc.py
models = dict(
    # ...
    model1=Quantize(model_path='/path/to/model1.onnx',
                    config_path='/path/to/model1.yaml'),
)
# 2. prepare your YAML config model1.yaml (see configs in ./inc_configs)
# 3. quantize your model
python quantize-inc.py model1
Y
Yuantao Feng 已提交
53
```
54 55 56

## Dataset
Some models are quantized with extra datasets.
57
- [MP-PalmDet](../../models/palm_detection_mediapipe) and [MP-HandPose](../../models/handpose_estimation_mediapipe) are quantized with evaluation set of [FreiHAND](https://lmb.informatik.uni-freiburg.de/resources/datasets/FreihandDataset.en.html). Download the dataset from [this link](https://lmb.informatik.uni-freiburg.de/data/freihand/FreiHAND_pub_v2_eval.zip). Unpack it and replace `path/to/dataset` with the path to `FreiHAND_pub_v2_eval/evaluation/rgb`.