convert_model

功能说明

根据用户自己计算得到的量化因子以及Caffe模型,适配成可以在昇腾AI处理器上做在线推理的Deploy量化部署模型和可以在Caffe环境下进行精度仿真的Fakequant量化模型。

约束说明

函数原型

convert_model(model_file,weights_file,scale_offset_record_file,save_path)

参数说明

参数名

输入/返回值

含义

使用限制

model_file

输入

用户Caffe模型的定义文件,格式为.prototxt。

数据类型:string

使用约束:model_file中包含的用于推理的层,LayerParameter设置满足推理要求,比如BatchNorm层的use_global_stats必须设置为1。

weights_file

输入

用户训练好的Caffe模型权重文件,格式为.caffemodel。

数据类型:string

scale_offset_record_file

输入

用户计算得到的量化因子记录文件,格式为.txt。

数据类型:string

save_path

输入

模型存放路径。该路径需要包含模型名前缀,例如./quantized_model/*model

数据类型:string

返回值说明

无。

函数输出

重新执行适配时,该接口输出的上述文件将会被覆盖。

调用示例

from amct_caffe import convert_model
convert_model(model_file='ResNet-50-deploy.prototxt',
              weights_file='ResNet-50-weights.caffemodel',
              scale_offset_record_file='record.txt',
              save_path='./quantized_model/model')