将ONNX量化模型适配为CANN支持的量化模型。
当前仅支持对QAT模型中包含QuantizeLinear和DequantizeLinear两类FakeQuant层结构的模型进行适配,且仅权重支持per-channel量化,成对的QuantizeLinear、DequantizeLinear层需要存在相同的量化因子。
convert_qat_model(model_file, save_path, record_file=None)
参数名 |
输入/返回值 |
含义 |
使用限制 |
---|---|---|---|
model_file |
输入 |
待适配的.onnx格式模型文件路径。 |
数据类型:string |
save_path |
输入 |
模型存放路径。该路径需要包含模型名前缀,例如./quantized_model/*model。 |
数据类型:string |
record_file |
输入 |
用户计算得到的量化因子记录文件路径,量化因子记录文件格式为.txt。 |
数据类型:string 默认值为:None |
无。
import amct_onnx as amct model_file = "./pre_model/mobilenet_v2_qat.onnx" save_path="./results/model" amct.convert_qat_model(model_file, save_path)