quantize_preprocess

Description

Preprocesses the quantization of a graph based on the quantization configuration file, inserts the balanced quantization operators, generates a balanced-factor record file record_file, and returns an ONNX model ready for calibration.

Prototype

quantize_preprocess(config_file, record_file, model_file, modified_onnx_file)

Command-Line Options

Option

Input/Return

Description

Restriction

config_file

Input

User-defined quantization configuration file, which specifies the configuration of each layer to be quantized.

A string

record_file

Input

Directory of the balanced-factor record file, including the file name.

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

Return Value

None.

Outputs

None

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import amct_onnx as amct

model_file = "resnet101.onnx"
tensor_balance_factor_record_file  = os.path.join(TMP, 'tensor_balance_factor_record.txt')
modified_model = os.path.join(TMP, 'modified_model.onnx')
config_file="./configs/config.json"
# Insert the quantization API.
amct.quantize_preprocess(config_file,
                         tensor_balance_factor_record_file,
                         model_file,
                         modified_model)