产品 |
是否支持 |
---|---|
x |
|
x |
|
x |
|
x |
注:标记“x”的产品,调用接口不会报错,但是获取不到性能收益。
训练后量化接口,根据用户输入的模型、配置文件进行自动非均匀量化,搜索得到一个满足目标精度的非均匀量化配置,输出可以在Caffe环境下做精度仿真的fake_quant模型,和可在昇腾AI处理器上做在线推理的deploy模型。
1 | auto_nuq(model_file, weights_file, nuq_evaluator, config_file, scale_offset_record_file, save_dir) |
参数名 |
输入/输出 |
说明 |
---|---|---|
model_file |
输入 |
含义:用户Caffe模型的定义文件,格式为.prototxt。 数据类型:string |
weights_file |
输入 |
含义:用户训练好的Caffe模型权重文件,格式为.caffemodel。 数据类型:string |
nuq_evaluator |
输入 |
含义:自动非均匀量化评估的python实例。 数据类型:python instance |
config_file |
输入 |
含义:用户生成的量化配置文件。 数据类型:string |
scale_offset_record_file |
输入 |
含义:存储量化因子的文件,如果该文件存在,会被重写。 数据类型:string |
save_dir |
输入 |
含义:模型存放路径。该路径需要包含模型名前缀,例如./quantized_model/*model。 数据类型:string |
无
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import amct_caffe as amct from amct_caffe.auto_nuq import AutoNuqEvaluatorBase class AutoNuqEvaluator(AutoNuqEvaluatorBase): def __init__(self, evaluate_batch_num): self.evaluate_batch_num = evaluate_batch_num def eval_model(self, model_file, weights_file, batch_num): return do_benchmark_test(args, model_file, weights_file, batch_num) def is_satisfied(self, original_metric, new_metric): # the loss of top1 acc need to be less than 1% if (original_metric - new_metric) *100<1: return True return False evaluator = AutoNuqEvaluator(1000) amct.auto_nuq( model_file, weights_file, evaluator, config_json_file, scale_offset_record_file, './results/Resnet50') |
落盘文件说明:
重新执行量化时,该接口输出的上述文件将会被覆盖。