---
title: quantize_model
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/devaids/amct/atlasamct_16_0154.html
sourcePath: /source/zh/canncommercial/900/devaids/amct/atlasamct_16_0154.html
indexId: 50922047044765a33c55ed5cebb8e0c1191ca4c4de128057922746ef7d31f25165
---
# quantize_model

#### 产品支持情况

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


#### 功能说明

将输入的待量化的图结构按照给定的量化配置文件进行量化处理，在传入的图结构中插入权重量化，以及数据量化等相关的算子，生成量化因子记录文件record_file，返回修改后的ONNX校准模型。


#### 函数原型

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


#### 参数说明

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


#### 返回值说明

无


#### 调用示例

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