Skip to content

Commit bdd60c2

Browse files
authored
Introduce Preprocessing for Optimized Quantization in quantize-ort.py (#238)
* Add preprocessing with optimization before quantization * Clean up unintended changed --------- Co-authored-by: Tim-Siu <[email protected]>
1 parent 821a8df commit bdd60c2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/quantize/quantize-ort.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import onnx
1313
from onnx import version_converter
1414
import onnxruntime
15-
from onnxruntime.quantization import quantize_static, CalibrationDataReader, QuantType, QuantFormat
15+
from onnxruntime.quantization import quantize_static, CalibrationDataReader, QuantType, QuantFormat, quant_pre_process
1616

1717
from transform import Compose, Resize, CenterCrop, Normalize, ColorConvert, HandAlign
1818

@@ -76,6 +76,7 @@ def check_opset(self):
7676
def run(self):
7777
print('Quantizing {}: act_type {}, wt_type {}'.format(self.model_path, self.act_type, self.wt_type))
7878
new_model_path = self.check_opset()
79+
quant_pre_process(new_model_path, new_model_path)
7980
output_name = '{}_{}.onnx'.format(self.model_path[:-5], self.wt_type)
8081
quantize_static(new_model_path, output_name, self.dr,
8182
quant_format=QuantFormat.QOperator, # start from onnxruntime==1.11.0, quant_format is set to QuantFormat.QDQ by default, which performs fake quantization

0 commit comments

Comments
 (0)