# quantize_preprocess

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |


#### 功能说明

量化数据均衡预处理接口，将输入的待量化的图结构按照给定的量化配置文件进行训练后量化预处理，在传入的图结构中插入均衡量化算子，生成均衡量化因子记录文件record_file，返回修改后的ONNX校准模型。


#### 函数原型

```
quantize_preprocess(config_file, record_file, model_file, modified_onnx_file)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| config\_file | 输入 | 含义：用户生成的量化配置文件，用于指定模型network中量化层的配置情况。 数据类型：string |
| record\_file | 输入 | 含义：均衡量化因子记录文件路径及名称。 数据类型：string |
| model\_file | 输入 | 含义：用户原始onnx模型文件或者通过create\_quant\_config生成的updated模型。 数据类型：string |
| modified\_onnx\_file | 输入 | 含义：文件名，用于存储待执行数据量化的ONNX校准模型。 数据类型：string |


#### 返回值说明

无


#### 调用示例

```
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"
# 插入量化API
amct.quantize_preprocess(config_file,
                         tensor_balance_factor_record_file,
                         model_file,
                         modified_model)
```
