save_quant_retrain_model
功能说明
量化感知训练接口,根据用户最终的重训练好的模型,插入AscendQuant、AscendDequant等算子,生成最终fake quant仿真模型和deploy部署模型。
约束说明
无。
函数原型
save_quant_retrain_model(retrained_model_file, retrained_weights_file, save_type, save_path, scale_offset_record_file = None, config_file = None)
参数说明
| 参数名 | 输入/返回值 | 含义 | 使用限制 | 
|---|---|---|---|
| retrained_model_file | 输入 | 用户重训练好的Caffe模型的定义文件,格式为.prototxt。 | 数据类型:string 使用约束:retrained_model_file中包含的用于推理的层,LayerParameter设置满足推理要求,比如BatchNorm层的use_global_stats必须设置为1。 | 
| retrained_weights_file | 输入 | 用户重训练好的Caffe模型的权重文件,格式为.caffemodel。 | 数据类型:string | 
| save_type | 输入 | 保存模型的类型: 
 | 数据类型:string | 
| save_path | 输入 | 模型存放路径。 该路径需要包含模型名前缀,例如./quantized_model/*model。 | 数据类型:string | 
| scale_offset_record_file | 输入 | 存储量化因子的文件。 | 数据类型:string。默认已初始化,传None | 
| config_file | 输入 | 量化配置文件。 | 数据类型:string。默认已初始化,传None | 
返回值说明
无。
函数输出
- 精度仿真模型文件:一个模型定义文件,一个模型权重文件,文件名中包含fake_quant;模型可在Caffe环境下做推理实现量化精度仿真。
- 部署模型文件:一个模型定义文件,一个模型权重文件,文件名中包含deploy;模型经过ATC工具转换后可部署到昇腾AI处理器上。
调用示例
| 1 2 3 4 5 6 | from amct_caffe import amct retrained_model_file = './pre_model/retrained_resnet50.prototxt' retrained_weights_file = './pre_model/resnet50_solver_iter_35000.caffemodel' scale_offset_record_file = './record.txt' # 插入API,将重训练的模型保存为prototxt模型文件以及caffemodel权重文件,在./result中生成四个文件:model_fake_quant_model.prototxt,model_fake_quant_weights.caffemodel,model_deploy_model.prototxt,model_deploy_weights.prototxt amct.save_quant_retrain_model(retrained_model_file, retrained_weights_file, 'Both', './result/model', scale_offset_record_file, config_json_file) | 
父主题: 量化感知训练接口