中文|English
此链接提供Yolov3 TensorFlow模型在NPU上离线推理的脚本和方法
此案例仅为您学习Ascend软件栈提供参考,不用于商业目的。
在开始之前,请注意以下适配条件。如果不匹配,可能导致运行失败。
Conditions | Need |
---|---|
CANN版本 | >=5.0.3 |
芯片平台 | Ascend310/Ascend310P3 |
第三方依赖 | 请参考 'requirements.txt' |
git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git
cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL
opencv-python==4.2.0.34
数据集 例如,与官方实施相比,我们使用 get_coco_dataset.sh 准备我们的数据集。
注释文件
cd scripts
Using script generate coco2014_minival.txt
file. Modify the path in coco_minival_anns.py
and 5k.txt
, then execute:
python3 coco_minival_anns.py
One line for one image, in the format like image_index image_absolute_path img_width img_height box_1 box_2 ... box_n
.
Box_x format:
label_index x_min y_min x_max y_max
. (The origin of coordinates is at the left top corner, left top => (xmin, ymin), right bottom => (xmax, ymax).)image_index
is the line index which starts from zero. label_index
is in range [0, class_num - 1].例如:
0 xxx/xxx/a.jpg 1920 1080 0 453 369 473 391 1 588 245 608 268
1 xxx/xxx/b.jpg 1920 1080 1 466 403 485 422 2 793 300 809 320
...
离线模型转换
环境变量设置
请参考说明,设置环境变量
Pb模型转换为om模型
For Ascend310:
atc --model=yolov3_tf.pb --framework=3 --output=yolov3_tf_aipp --output_type=FP32 --soc_version=Ascend310 --input_shape="input:1,416,416,3" --log=info --insert_op_conf=yolov3_tf_aipp.cfg
For Ascend310P3:
atc --model=yolov3_tf.pb --framework=3 --output=yolov3_tf_aipp --output_type=FP32 --soc_version=Ascend310P3 --input_shape="input:1,416,416,3" --log=info --insert_op_conf=yolov3_tf_aipp.cfg
编译程序
For Ascend310:
unset ASCEND310P3_DVPP
bash build.sh
For Ascend310P3:
export ASCEND310P3_DVPP=1
bash build.sh
开始运行:
cd scripts
bash benchmark_tf.sh --batchSize=1 --modelType=yolov3 --imgType=raw --precision=fp16 --outputType=fp32 --useDvpp=1 --deviceId=0 --modelPath=yolov3_tf_aipp.om --trueValuePath=instance_val2014.json --imgInfoFile=coco2014_minival.txt --classNamePath=../../coco.names
本结果是通过运行上面适配的推理脚本获得的。要获得相同的结果,请按照《快速指南》中的步骤操作。
IoU=0.5
model | Npu_nums | mAP |
---|---|---|
Yolov3 | 1 | 55.3% |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。