动态BatchSize OM推理
以档位1 2 4 8档为例,设置档位为2,本程序将获取实际模型输入组Batch,每2个输入为一组,进行组Batch。
示例命令:
python3 -m ais_bench --model ./inference/om/dynamic_batch_size_det.om --input ./inference/input/ --output ./inference/output/ --dymBatch 2
推理结果:
输出结果:
执行完毕后,输出会被保存在 ./inference/output/路径下:
inference/output/
├── 2025_03_17-11_11_48
├── image_0.bin
└── 2025_03_17-11_11_48_summary.json
动态分辨率 OM推理
以档位224,224;448,448档为例,设置档位为224,224,本程序将获取实际模型输入组Batch。
示例命令:
python3 -m ais_bench --model ./inference/om/dynamic_image_size_det.om --input ./inference/input/ --output ./inference/output/ --dymHW 224,224
推理结果:
输出结果:
执行完毕后,输出会被保存在 ./inference/output/路径下:
inference/output/
├── 2025_03_17-11_47_25
├── image_0.bin
└── 2025_03_17-11_47_25_summary.json
动态维度 OM推理
固定维度模式
以设置档位1,3,224,224为例,本程序将获取实际模型输入组Batch。
示例命令:
python3 -m ais_bench --model ./inference/om/dynamic_dims_det.om --input ./inference/input/ --output ./inference/output/ --dymDims x:1,3,224,224
推理结果:
输出结果:
执行完毕后,输出会被保存在 ./inference/output/路径下:
inference/output/
├── 2025_03_17-11_53_04
├── image_0.bin
└── 2025_03_17-11_53_04_summary.json
自动设置维度模式
动态维度模型输入数据的Shape可能是不固定的,比如一个输入文件Shape为1,3,224,224,另一个输入文件Shape为 1,3,448,448。若两个文件同时推理,则需要设置两次动态Shape参数,当前不支持该操作。针对该场景,增加动态Dims模式,可以根据输入文件的Shape信息,自动设置模型的Shape参数。
示例命令:
python3 -m ais_bench --model ./inference/om/dynamic_dims_det.om --input ./inference/input/ --output ./inference/output/ --auto_set_dymdims_mode 1
推理结果:
输入文件:
# 输入的input文件夹内容如下
ls ./inference/input/
image_1_224_224.npy image_1_448_448.npy
输出结果:
执行完毕后,输出会被保存在 ./inference/output/路径下:
inference/output/
├── 2025_03_18-23_54_55
├── image_1_224_224_0.bin
├── image_1_448_448_0.bin
└── 2025_03_18-23_54_55_summary.json
动态shape OM推理
固定shape模式
以ATC设置[1~8,3,224~448,224~448],设置档位1,3,256,256为例,本程序将获取实际模型输入组Batch。
动态Shape的输出大小通常为0,建议通过--outputSize参数设置对应输出的内存大小。
示例命令:
python3 -m ais_bench --model ./inference/om/dynamic_shape_det_linux_aarch64.om --input ./inference/image.npy --output ./inference/output/ --dymShape x:1,3,256,256 --outputSize 10000
推理结果:
输出结果:
执行完毕后,输出会被保存在 ./inference/output/路径下:
inference/output/
├── 2025_03_19-00_12_07
├── image_0.bin
└── 2025_03_19-00_12_07_summary.json
自动设置Shape模式
动态Shape模型输入数据的Shape可能是不固定的,比如输入文件Shape分别为1,3,224,224;1,3,256,256;1,3,448,448。若三个文件同时推理,则需要设置三次动态Shape参数,当前不支持该操作。针对该场景,增加动态Shape模式,可以根据输入文件的Shape信息,自动设置模型的Shape参数。
示例命令:
python3 -m ais_bench --model ./inference/om/dynamic_shape_det_linux_aarch64.om --auto_set_dymshape_mode 1 --input ./inference/input/ --output ./inference/output/ --outputSize 10000
推理结果:
输入文件:
# 输入的input文件夹内容如下
ls ./inference/input/
image_1_224_224.npy image_1_256_256.npy image_1_448_448.npy
输出结果:
执行完毕后,输出会被保存在 ./inference/output/路径下:
inference/output/
├── 2025_03_19-00_21_55
├── image_1_224_224_0.bin
├── image_1_256_256_0.bin
├── image_1_448_448_0.bin
└── 2025_03_19-00_21_55_summary.json
注意:该场景下的输入文件必须为npy格式,如果是bin文件将获取不到真实的Shape信息。
profiler或dump场景
--profiler参数和--dump参数,必须要增加--output参数,指示输出路径。
--profiler和--dump可以分别使用,但不能同时启用。
python3 -m ais_bench --model ./inference/om/det.om --output ./inference/output/ --dump 1
python3 -m ais_bench --model ./inference/om/det.om --output ./inference/output/ --profiler 1
常见问题
未设置环境变量
每次使用离线推理前务必先设置环境变量:
source /usr/local/Ascend/ascend-toolkit/set_env.sh
实际输入HW和OM模型不一致
报错信息:
错误原因:
det.om模型的输入input_shape=x:1,3,224,224;而image.npy的输入为:1,3,256,256。
实际输入Dims和OM模型不一致
报错信息:
错误原因:
dynamic_dims_det.om模型的输入dynamic_dims="1,224,224;8,448,448";而实际的输入为:1,3,224,224;1,3,448,448。
动态OM模型未设置动态参数
报错信息:
错误原因:
使用动态OM模型(包括动态BatchSize、动态分辨率、动态维度、动态shape)推理,但并未设置相关的动态参数。
CANN包版本老旧
报错信息:
错误原因:
CANN包版本老旧,参考“环境准备->更新CANN包”章节更换CANN版本。
API推理
请参考ais_bench interface python API使用指南:
https://gitee.com/ascend/tools/blob/master/ais-bench_workload...
参考链接
- ONNX离线推理流程:
https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyT... - 性能优化案例:
https://gitee.com/ascend/ModelZoo-PyTorch/blob/master/ACL_PyT... - ais_bench推理工具使用指南:
https://gitee.com/ascend/tools/blob/master/ais-bench_workload... - ATC 工具使用指南:
https://www.hiascend.com/doc_center/source/zh/canncommercial/...
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。