以下介绍通过ATC模型转换工具获取离线模型的操作步骤,更多操作请参见《ATC离线模型编译工具用户指南》。
例如:resnet50.prototxt和resnet50.caffemodel
atc --model=$HOME/module/resnet50.prototxt --weight=$HOME/module/resnet50.caffemodel --framework=0 --output=$HOME/module/out/caffe_resnet50_on --soc_version=<soc_version>
模型转换时,算子融合功能默认开启,无需配置。
1 |
ATC run success
|
成功执行命令后,在$HOME/module/out/目录下生成离线模型(如:caffe_resnet50_on.om)。
atc --model=$HOME/module/resnet50.prototxt --weight=$HOME/module/resnet50.caffemodel --framework=0 --output=$HOME/module/out/caffe_resnet50_off --soc_version=<soc_version> --fusion_switch_file=$HOME/module/fusion_switch.cfg
关闭算子融合功能需要通过--fusion_switch_file参数指定算子融合规则配置文件(如fusion_switch.cfg),并在配置文件中关闭算子融合。融合规则配置文件关闭配置如下:
{ "Switch":{ "GraphFusion":{ "ALL":"off" }, "UBFusion":{ "ALL":"off" } } }
1 |
ATC run success
|
成功执行命令后,在$HOME/module/out/目录下生成离线模型(如:caffe_resnet50_off.om)。
以下仅以Caffe模型为例介绍通过AMCT工具获取量化信息文件的操作步骤,更多操作请参见《AMCT模型压缩工具用户指南》。
例如:resnet50.prototxt和resnet50.caffemodel
cd data mkdir image && cd image wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/models/amct_acl/classification/calibration.rar unrar e calibration.rar
python3 ./src/process_data.py
执行完成后,在data目录会生成新的calibration目录,并在该目录生成calibration.bin格式数据集。
amct_caffe calibration --model=./model/resnet50.prototxt --weights=./model/resnet50.caffemodel --save_path=./results --input_shape="data:1,3,224,224" --data_dir="./data/calibration" --data_types="float32"
1 2 |
INFO - [AMCT]:[Utils]: The weights_file is saved in $HOME/xxx/results/resnet50_fake_quant_weights.caffemodel
INFO - [AMCT]:[Utils]: The model_file is saved in $HOME/xxx/results/resnet50_fake_quant_model.prototxt
|