Introduce Preprocessing for Optimized Quantization in `quantize-ort.py` (#238)
Browse files* Add preprocessing with optimization before quantization
* Clean up unintended changed
---------
Co-authored-by: Tim-Siu <[email protected]>
tools/quantize/quantize-ort.py
CHANGED
@@ -12,7 +12,7 @@ import cv2 as cv
|
|
12 |
import onnx
|
13 |
from onnx import version_converter
|
14 |
import onnxruntime
|
15 |
-
from onnxruntime.quantization import quantize_static, CalibrationDataReader, QuantType, QuantFormat
|
16 |
|
17 |
from transform import Compose, Resize, CenterCrop, Normalize, ColorConvert, HandAlign
|
18 |
|
@@ -76,6 +76,7 @@ class Quantize:
|
|
76 |
def run(self):
|
77 |
print('Quantizing {}: act_type {}, wt_type {}'.format(self.model_path, self.act_type, self.wt_type))
|
78 |
new_model_path = self.check_opset()
|
|
|
79 |
output_name = '{}_{}.onnx'.format(self.model_path[:-5], self.wt_type)
|
80 |
quantize_static(new_model_path, output_name, self.dr,
|
81 |
quant_format=QuantFormat.QOperator, # start from onnxruntime==1.11.0, quant_format is set to QuantFormat.QDQ by default, which performs fake quantization
|
|
|
12 |
import onnx
|
13 |
from onnx import version_converter
|
14 |
import onnxruntime
|
15 |
+
from onnxruntime.quantization import quantize_static, CalibrationDataReader, QuantType, QuantFormat, quant_pre_process
|
16 |
|
17 |
from transform import Compose, Resize, CenterCrop, Normalize, ColorConvert, HandAlign
|
18 |
|
|
|
76 |
def run(self):
|
77 |
print('Quantizing {}: act_type {}, wt_type {}'.format(self.model_path, self.act_type, self.wt_type))
|
78 |
new_model_path = self.check_opset()
|
79 |
+
quant_pre_process(new_model_path, new_model_path)
|
80 |
output_name = '{}_{}.onnx'.format(self.model_path[:-5], self.wt_type)
|
81 |
quantize_static(new_model_path, output_name, self.dr,
|
82 |
quant_format=QuantFormat.QOperator, # start from onnxruntime==1.11.0, quant_format is set to QuantFormat.QDQ by default, which performs fake quantization
|