quantize_model
Function Usage
Quantizes a graph based on the quantization configuration file, inserts weight and activation quantization operators, generates a quantization factor record file record_file, and returns an ONNX model ready for calibration.
Prototype
quantize_model(config_file, model_file, modified_onnx_file, record_file)
Command-Line Options
Option |
Input/Return |
Meaning |
Restriction |
|---|---|---|---|
config_file |
Input |
User-defined quantization configuration file, which specifies the configuration of each layer to be quantized. |
A string |
model_file |
Input |
Source ONNX model file or updated ONNX model file generated by create_quant_config. |
A string |
modified_onnx_file |
Input |
File name of the ONNX model ready for calibration, whose activations are to be quantized. |
A string |
record_file |
Input |
Directory of the quantization factor record file, including the file name. |
A string. |
Return Value
None
Example
1 2 3 4 5 6 7 8 9 10 11 | import amct_onnx as amct model_file = "resnet101.onnx" scale_offset_record_file = os.path.join(TMP, 'scale_offset_record.txt') modified_model = os.path.join(TMP, 'modified_model.onnx') config_file="./configs/config.json" # Insert the quantization API. amct.quantize_model(config_file, model_file, modified_model, scale_offset_record_file) |