From 64f7c7524252bf8448002e14e14cc30bdc343c6c Mon Sep 17 00:00:00 2001 From: mr_melos <1595862940@qq.com> Date: Mon, 25 Apr 2022 20:27:44 +0800 Subject: [PATCH 1/9] =?UTF-8?q?GFocalV2=E7=A6=BB=E7=BA=BF=E6=8E=A8?= =?UTF-8?q?=E7=90=86710=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md | 8 ++++---- .../cv/detection/GFocalV2/gfocal_postprocess.py | 12 ++++++------ .../cv/detection/GFocalV2/test/eval_acc_perf.sh | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index 7b2c3f63d1..3a33d8e3f0 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -42,8 +42,8 @@ root │ │ ├── val2017 ``` -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录 +5.[获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) +参考链接教程安装msame推理工具 ## 2 离线推理 @@ -53,8 +53,8 @@ bash test/pth2om.sh bash test/eval_acc_perf.sh --datasets_path=/root/datasets ``` **评测结果:** -| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | +| 模型 | 在线推理精度 | 710离线推理精度 | 710性能 | 310性能 | | :------: | :------: | :------: | :------: | :------: | -| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 7.9fps | 12.071fps | +| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 9.59fps | 4.48fps | 备注:离线模型不支持多batch。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py index 49b2e77560..922a8a8d73 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py @@ -1,4 +1,4 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2022 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -60,7 +60,7 @@ if __name__ == '__main__': cnt = 0 for ids in coco_dataset.img_ids: cnt = cnt + 1 - bin_file = glob.glob(bin_path + '/*0' + str(ids) + '_1.bin')[0] + bin_file = glob.glob(bin_path + '/*0' + str(ids) + '_output_0.txt')[0] bin_file = bin_file[bin_file.rfind('/') + 1:] bin_file = bin_file[:bin_file.rfind('_')] print(cnt - 1, bin_file) @@ -69,11 +69,11 @@ if __name__ == '__main__': res_buff = [] bbox_results = [] cls_segms = [] - if os.path.exists(path_base + "_" + "1" + ".bin") and os.path.exists(path_base + "_" + "2" + ".bin"): - bboxes = np.fromfile(path_base + "_" + str(flags.net_out_num - 1) + ".bin", dtype="float32") + if os.path.exists(path_base + "_" + "output_0" + ".txt") and os.path.exists(path_base + "_" + "output_1" + ".txt"): + bboxes = np.loadtxt(path_base + "_output_" + str(flags.net_out_num - 3) + ".txt", dtype="float32") bboxes = np.reshape(bboxes, [100, 5]) bboxes = torch.from_numpy(bboxes) - labels = np.fromfile(path_base + "_" + str(flags.net_out_num - 2) + ".bin", dtype="int64") + labels = np.loadtxt(path_base + "_output_" + str(flags.net_out_num - 2) + ".txt", dtype="int64") labels = np.reshape(labels, [100, 1]) labels = torch.from_numpy(labels) @@ -81,7 +81,7 @@ if __name__ == '__main__': bboxes = postprocess_bboxes(bboxes, img_size_dict[bin_file], flags.net_input_width, flags.net_input_height) bbox_results = [bbox2result(bboxes, labels[:, 0], 80)] else: - print("[ERROR] file not exist", path_base + "_" + str(1) + ".bin",path_base + "_" + str(2) + ".bin") + print("[ERROR] file not exist", path_base + "_output_" + str(1) + ".txt",path_base + "_output_" + str(2) + ".txt") result = bbox_results results.extend(result) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh index a25afb777e..c9d1782de2 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh @@ -13,7 +13,7 @@ if [ $? != 0 ]; then echo "fail!" exit -1 fi -python3.7 get_info.py bin val2017_bin gfocal.info 1216 800 +python3.7 get_info.py bin ${datasets_path}/coco/val2017_bin gfocal.info 1216 800 if [ $? != 0 ]; then echo "fail!" exit -1 @@ -24,13 +24,13 @@ if [ $? != 0 ]; then exit -1 fi source env.sh -rm -rf result/dumpOutput_device0 -./benchmark.${arch} -model_type=vision -om_path=gfocal_bs1.om -device_id=0 -batch_size=1 -input_text_path=gfocal.info -input_width=1216 -input_height=800 -useDvpp=false -output_binary=true +rm -rf ${datasets_path}/coco/val2017_bin +./msame --model "./gfocal_bs1.om" --input "${datasets_path}/coco/val2017_bin" --output "./out/" --outfmt TXT if [ $? != 0 ]; then echo "fail!" exit -1 fi -python3.7 gfocal_postprocess.py --bin_data_path=./result/dumpOutput_device0/ --test_annotation=gfocal_jpeg.info --net_out_num=3 --net_input_height=800 --net_input_width=1216 +python3.7 gfocal_postprocess.py --bin_data_path=./out/ --test_annotation=gfocal_jpeg.info --net_out_num=3 --net_input_height=800 --net_input_width=1216 if [ $? != 0 ]; then echo "fail!" exit -1 -- Gitee From e059f9fb37f9ae22ba53cfbaca4af33694619bb0 Mon Sep 17 00:00:00 2001 From: mr_melos <1595862940@qq.com> Date: Tue, 26 Apr 2022 15:57:59 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86GPU=E6=8E=A8?= =?UTF-8?q?=E7=90=86=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BF=AE=E6=AD=A3=E4=BA=86?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md | 8 ++++---- .../contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh | 9 ++++++--- ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index 3a33d8e3f0..0ccf7dcadb 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -50,11 +50,11 @@ root 310上执行,执行时使npu-smi info查看设备状态,确保device空闲 ``` bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +bash test/eval_acc_perf.sh --datasets_path=/root/dataset ``` **评测结果:** -| 模型 | 在线推理精度 | 710离线推理精度 | 710性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 9.59fps | 4.48fps | +| 模型 | 在线推理精度 | 710离线推理精度 | 710性能 | 310性能 |T4性能 | +| :------: | :------: | :------: | :------: | :------: | :------: | +| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 9.59fps | 4.48fps | 9.4fps | 备注:离线模型不支持多batch。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh index c9d1782de2..1cd7e79c58 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh @@ -24,13 +24,16 @@ if [ $? != 0 ]; then exit -1 fi source env.sh -rm -rf ${datasets_path}/coco/val2017_bin -./msame --model "./gfocal_bs1.om" --input "${datasets_path}/coco/val2017_bin" --output "./out/" --outfmt TXT +rm -rf ./val2017_bin +./msame/out/msame --model "./gfocal_bs1.om" --input "./val2017_bin" --output "./out/" --outfmt TXT if [ $? != 0 ]; then echo "fail!" exit -1 fi -python3.7 gfocal_postprocess.py --bin_data_path=./out/ --test_annotation=gfocal_jpeg.info --net_out_num=3 --net_input_height=800 --net_input_width=1216 +cd ./out/2*/ +dir=${PWD##*/} +cd ../../ +python3.7 gfocal_postprocess.py --bin_data_path=./out/${dir} --test_annotation=gfocal_jpeg.info --net_out_num=3 --net_input_height=800 --net_input_width=1216 if [ $? != 0 ]; then echo "fail!" exit -1 diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py index b9c74f41d7..6da8978fc3 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py @@ -29,4 +29,4 @@ if __name__ == '__main__': content = f.read() txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file + print('710 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file -- Gitee From 411d38bd443e26d95961b18dd4a4d2a6d34f6df5 Mon Sep 17 00:00:00 2001 From: mr_melos <1595862940@qq.com> Date: Thu, 5 May 2022 17:12:16 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86readme=E7=9A=843?= =?UTF-8?q?10=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index 0ccf7dcadb..d23e7afa60 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -55,6 +55,6 @@ bash test/eval_acc_perf.sh --datasets_path=/root/dataset **评测结果:** | 模型 | 在线推理精度 | 710离线推理精度 | 710性能 | 310性能 |T4性能 | | :------: | :------: | :------: | :------: | :------: | :------: | -| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 9.59fps | 4.48fps | 9.4fps | +| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 9.59fps | 17.92fps | 9.4fps | 备注:离线模型不支持多batch。 \ No newline at end of file -- Gitee From aaba1f829b79c226b28b35d55590178ff82d1994 Mon Sep 17 00:00:00 2001 From: mr-melos <1595862940@qq.com> Date: Tue, 9 Aug 2022 23:35:01 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=84=E4=BC=B0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cv/detection/GFocalV2/gfocal_postprocess.py | 2 +- .../cv/detection/GFocalV2/test/eval_acc_perf.sh | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py index 922a8a8d73..454b43fb29 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py @@ -62,7 +62,7 @@ if __name__ == '__main__': cnt = cnt + 1 bin_file = glob.glob(bin_path + '/*0' + str(ids) + '_output_0.txt')[0] bin_file = bin_file[bin_file.rfind('/') + 1:] - bin_file = bin_file[:bin_file.rfind('_')] + bin_file = bin_file[:bin_file.find('_')] print(cnt - 1, bin_file) path_base = os.path.join(bin_path, bin_file) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh index 1cd7e79c58..ba2fa14e5b 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/eval_acc_perf.sh @@ -23,17 +23,15 @@ if [ $? != 0 ]; then echo "fail!" exit -1 fi -source env.sh -rm -rf ./val2017_bin -./msame/out/msame --model "./gfocal_bs1.om" --input "./val2017_bin" --output "./out/" --outfmt TXT +source /usr/local/Ascend/ascend-toolkit/set_env.sh +rm -rf ./out/ +./tools/msame/out/msame --model "./gfocal_bs1.om" --input "./val2017_bin" --output "./out/" --outfmt TXT if [ $? != 0 ]; then echo "fail!" exit -1 fi -cd ./out/2*/ -dir=${PWD##*/} -cd ../../ -python3.7 gfocal_postprocess.py --bin_data_path=./out/${dir} --test_annotation=gfocal_jpeg.info --net_out_num=3 --net_input_height=800 --net_input_width=1216 + +python3.7 gfocal_postprocess.py --bin_data_path=./out/2* --test_annotation=gfocal_jpeg.info --net_out_num=3 --net_input_height=800 --net_input_width=1216 if [ $? != 0 ]; then echo "fail!" exit -1 -- Gitee From 0e0d905a0da718aac787a7638de38b873c0fa046 Mon Sep 17 00:00:00 2001 From: mr-melos <1595862940@qq.com> Date: Wed, 10 Aug 2022 13:07:40 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contrib/cv/detection/GFocalV2/README.md | 195 ++++++++++++++++-- .../cv/detection/GFocalV2/requirements.txt | 4 +- .../cv/detection/GFocalV2/test/pth2om.sh | 2 +- 3 files changed, 176 insertions(+), 25 deletions(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index d23e7afa60..8325382890 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -1,23 +1,93 @@ # GFocalV2模型PyTorch离线推理指导 -## 1 环境准备 +- [GFocalV2模型PyTorch离线推理指导](#GFocalV2模型PyTorch离线推理指导) + - [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) + - [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) + - [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) + - [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成预处理数据集信息文件](#43-生成预处理数据集信息文件) + - [5 离线推理](#5-离线推理) + - [5.1 msame工具概述](#51-msame工具概述) + - [5.2 离线推理](#52-离线推理) + - [6 精度对比](#6-精度对比) + - [7 性能对比](#7-性能对比) + - [7.1 310P性能数据](#71-310p性能数据) + - [7.2 T4性能数据](#72-t4性能数据) + - [7.3 性能对比](#73-性能对比) -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[GfocalV2论文](https://arxiv.org/abs/1807.01544) +论文主要引入边界框不确定性的统计量来高效地指导定位质量估计,从而提升one-stage的检测器性能 + +### 1.2 代码地址 + +[GfocalV2 Pytorch实现代码](https://github.com/implus/GFocalV2) ``` -pip3.7 install -r requirements.txt +branch=master +commit_id=bfcc2b9fbbcad714cff59dacc8fb1111ce381cda ``` -说明:PyTorch选用开源1.8.0版本 +## 2 环境说明 +- **[深度学习框架](#21-深度学习框架)** -2.获取,修改与安装开源模型代码 -安装mmcv -```shell -git clone https://github.com/open-mmlab/mmcv -b v1.2.7 -cd mmcv -MMCV_WITH_OPS=1 pip3.7 install -e . -cd .. +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN == 5.1.RC1 +pytorch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +mmcv-full == 1.2.4 +mmdet == 2.6.0 +opencv-python == 4.5.1.48 +numpy == 1.21.6 +pillow == 7.2.0 +``` + +安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip install -r requirements.txt ``` + + + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + + +### 3.1 pth转onnx模型 + +1.获取pth权重文件 + +[gfocalv2预训练的pth权重文件](https://drive.google.com/file/d/1wSE9-c7tcQwIDPC6Vm_yfOokdPfmYmy7/view?usp=sharing) + +2.获取GFocalV2源码 + 获取GFocalV2代码 ``` git clone https://github.com/implus/GFocalV2.git -b master @@ -27,12 +97,50 @@ patch -p1 < ../GFocalV2.diff python3.7 setup.py develop cd .. ``` +3.使用./GFocalV2/tools/pytorch2onnx.py进行onnx的转换,在目录下生成gfocal.onnx + +``` +python3.7 ./GFocalV2/tools/pytorch2onnx.py ./GFocalV2/configs/gfocal/gfocal_r50_fpn_1x.py ./gfocal_r50_fpn_1x.pth --output-file gfocal.onnx --input-img ./GFocalV2/demo/demo.jpg --shape 800 1216 --show +``` + + + +### 3.2 onnx转om模型 + +1.设置环境变量 + +``` +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` -3.获取权重文件 +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23310P424%7C251366513%7C22892968%7C251168373),需要指定输出节点以去除无用输出,可以使用netron开源可视化工具查看具体的输出节点名: -[gfocalv2预训练的pth权重文件](https://drive.google.com/file/d/1wSE9-c7tcQwIDPC6Vm_yfOokdPfmYmy7/view?usp=sharing) +使用atc将onnx模型 ${chip_name}可通过npu-smi info指令查看 + +执行ATC命令 + +```shell +atc --framework=5 --model=./gfocal.onnx --output=gfocal_bs1 --input_format=NCHW --input_shape="input.1:1,3,800,1216" --log=debug --soc_version=Ascend310P3 +``` +参数说明:\ +--model:为ONNX模型文件。 \ +--framework:5代表ONNX模型。\ +--output:输出的OM模型。\ +--input_format:输入数据的格式。\ +--input_shape:输入数据的shape。\ +--log:日志级别。\ +--soc_version:处理器型号。\ -4.数据集 +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用COCO数据集 [coco2017](https://cocodataset.org/#download),下载其中val2017图片及其标注文件,放入服务器/root/dataset/coco/文件夹,val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: ``` root @@ -41,20 +149,63 @@ root │ │ ├── annotations │ │ ├── val2017 ``` +### 4.2 数据集预处理 +1.预处理脚本gfocal_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +```shell +python3.7 gfocal_preprocess.py --image_src_path=${datasets_path}/coco/val2017 --bin_file_path=val2017_bin --model_input_height=800 --model_input_width=1216 +``` -5.[获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) -参考链接教程安装msame推理工具 +### 4.3 生成预处理数据集信息文件 +1.生成数据集信息文件脚本get_info.py -## 2 离线推理 +2.执行生成数据集信息脚本,生成数据集信息文件 -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +```shell +python3.7 get_info.py jpg ${datasets_path}/coco/val2017 gfocal_jpeg.info +``` +第一个参数为模型输入的类型,第二个参数为数据集路径,第三个为输出的info文件 + + +## 5 离线推理 +- **[msame工具概述](#51-msame工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 msame工具概述 + +msame工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[参考链接](https://gitee.com/ascend/tools/tree/master/msame#https://gitee.com/link?target=https%3A%2F%2Fobs-book.obs.cn-east-2.myhuaweicloud.com%2Fcjl%2Fmsame.zip) + +### 5.2 离线推理 +1.设置环境变量 + +``` +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` +2.将编译完成的可执行文件放到当前目录下,执行离线推理,执行时使npu-smi info查看设备状态,确保device空闲 + +```shell +./tools/msame/out/msame --model "./gfocal_bs1.om" --input "./val2017_bin" --output "./out/" --outfmt TXT +``` + +## 6 精度对比 +调用gfocal_postprocess.py: +```shell +python3.7 gfocal_postprocess.py --bin_data_path=./out/2* --test_annotation=gfocal_jpeg.info --net_out_num=3 --net_input_height=800 --net_input_width=1216 ``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/dataset +参数"--bin_data_path"为推理生成结果文件的路径。 +执行完后会打印出精度。 +## 7 性能对比 ``` **评测结果:** -| 模型 | 在线推理精度 | 710离线推理精度 | 710性能 | 310性能 |T4性能 | +| 模型 | 在线推理精度 | 310P离线推理精度 | 310P性能 | 310性能 |T4性能 | | :------: | :------: | :------: | :------: | :------: | :------: | -| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 9.59fps | 17.92fps | 9.4fps | +| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 34.49fps | 17.92fps | 9.4fps | +# 710性能是否超过基准: 是 +310P vs 310: bs1:710=(34.49/17.92) 1.92倍基准 +310P vs T4: bs1:710=(34.49/9.4) 3.67倍基准 +性能在310P上的性能超过310的1.2倍,超过T4性能的1.6倍,性能达标 备注:离线模型不支持多batch。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt b/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt index 7609cac2ce..475b8abc43 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt @@ -1,5 +1,5 @@ torch == 1.8.0 torchvision == 0.9.0 onnx == 1.9.0 -numpy == 1.19.4 -opencv-python == 4.4.0.46 \ No newline at end of file +numpy == 1.21.6 +opencv-python == 4.5.1.48 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/pth2om.sh b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/pth2om.sh index e484971191..81d2226855 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/pth2om.sh +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/pth2om.sh @@ -1,7 +1,7 @@ rm -rf gfocal.onnx python3.7 ./GFocalV2/tools/pytorch2onnx.py ./GFocalV2/configs/gfocal/gfocal_r50_fpn_1x.py ./gfocal_r50_fpn_1x.pth --output-file gfocal.onnx --input-img ./GFocalV2/demo/demo.jpg --shape 800 1216 --show source env.sh -atc --framework=5 --model=./gfocal.onnx --output=gfocal_bs1 --input_format=NCHW --input_shape="input.1:1,3,800,1216" --log=debug --soc_version=Ascend310 +atc --framework=5 --model=./gfocal.onnx --output=gfocal_bs1 --input_format=NCHW --input_shape="input.1:1,3,800,1216" --log=debug --soc_version=Ascend310P3 if [ -f "gfocal_bs1.om" ]; then echo "success" else -- Gitee From eb918ed3722488ecbffdb5bc9e2ba85208ea2e08 Mon Sep 17 00:00:00 2001 From: mr-melos <1595862940@qq.com> Date: Wed, 10 Aug 2022 13:10:31 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index 8325382890..c5f9fd6ecd 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -115,7 +115,7 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh 2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23310P424%7C251366513%7C22892968%7C251168373),需要指定输出节点以去除无用输出,可以使用netron开源可视化工具查看具体的输出节点名: -使用atc将onnx模型 ${chip_name}可通过npu-smi info指令查看 +使用atc将onnx模型转换为om模型 执行ATC命令 -- Gitee From 994cee4fe6cddfc6fb2d4c502c331a4e328b9e60 Mon Sep 17 00:00:00 2001 From: mr-melos <1595862940@qq.com> Date: Wed, 10 Aug 2022 14:31:47 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md | 6 +++--- .../contrib/cv/detection/GFocalV2/gfocal_postprocess.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index c5f9fd6ecd..2339afaf7d 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -49,7 +49,7 @@ commit_id=bfcc2b9fbbcad714cff59dacc8fb1111ce381cda ### 2.1 深度学习框架 ``` -CANN == 5.1.RC1 +CANN == 5.1.RC2 pytorch == 1.8.0 torchvision == 0.9.0 onnx == 1.9.0 @@ -115,12 +115,12 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh 2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23310P424%7C251366513%7C22892968%7C251168373),需要指定输出节点以去除无用输出,可以使用netron开源可视化工具查看具体的输出节点名: -使用atc将onnx模型转换为om模型 +使用atc将onnx模型转换为om模型 ${chip_name}可通过npu-smi info指令查看 执行ATC命令 ```shell -atc --framework=5 --model=./gfocal.onnx --output=gfocal_bs1 --input_format=NCHW --input_shape="input.1:1,3,800,1216" --log=debug --soc_version=Ascend310P3 +atc --framework=5 --model=./gfocal.onnx --output=gfocal_bs1 --input_format=NCHW --input_shape="input.1:1,3,800,1216" --log=debug --soc_version=Ascend${chip_name} ``` 参数说明:\ --model:为ONNX模型文件。 \ diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py index 454b43fb29..70cec06f3f 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py @@ -81,7 +81,7 @@ if __name__ == '__main__': bboxes = postprocess_bboxes(bboxes, img_size_dict[bin_file], flags.net_input_width, flags.net_input_height) bbox_results = [bbox2result(bboxes, labels[:, 0], 80)] else: - print("[ERROR] file not exist", path_base + "_output_" + str(1) + ".txt",path_base + "_output_" + str(2) + ".txt") + print("[ERROR] file not exist", path_base + "_output_" + str(0) + ".txt",path_base + "_output_" + str(1) + ".txt") result = bbox_results results.extend(result) -- Gitee From ba2ec8fcc11a040b6cdffad81a334460427ea649 Mon Sep 17 00:00:00 2001 From: mr-melos <1595862940@qq.com> Date: Wed, 10 Aug 2022 16:46:11 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contrib/cv/detection/GFocalV2/README.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index 2339afaf7d..6334dbecc4 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -117,6 +117,8 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh 使用atc将onnx模型转换为om模型 ${chip_name}可通过npu-smi info指令查看 +![输入图片说明](https://images.gitee.com/uploads/images/2022/0704/095450_881600a3_7629432.png "屏幕截图.png") + 执行ATC命令 ```shell @@ -198,6 +200,43 @@ python3.7 gfocal_postprocess.py --bin_data_path=./out/2* --test_annotation=gfoca 参数"--bin_data_path"为推理生成结果文件的路径。 执行完后会打印出精度。 ## 7 性能对比 + +- **[310性能数据](#71-310性能数据)** +- **[310P性能数据](#72-310P性能数据)** +- **[T4性能数据](#73-T4性能数据)** +- **[性能对比](#74-性能对比)** + +### 7.1 310性能数据 + +batch1的性能: + 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 + +``` +./tools/msame/out/msame --model "./gfocal_bs1.om" --input "./val2017_bin" --output "./out/" --outfmt TXT +``` +执行数据集推理,推理完成时显示推理时间。 +``` +Inference average time : 223.21ms +Inference average time without first time : 223.22ms +``` +由于310为四芯片,计算fps时使用4*1000/223.21=17.92fps + +### 7.2 310P性能数据 + +batch1的性能: + 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 + +``` +./tools/msame/out/msame --model "./gfocal_bs1.om" --input "./val2017_bin" --output "./out/" --outfmt TXT +``` +执行数据集推理,推理完成时显示推理时间。 +``` +Inference average time : 28.99ms +Inference average time without first time : 28.99ms +``` +计算fps时使用1000/28.99=34.49fps + +### 7.3 性能对比 ``` **评测结果:** | 模型 | 在线推理精度 | 310P离线推理精度 | 310P性能 | 310性能 |T4性能 | -- Gitee From bc5ba0f69ad2b18eb3c4081c2ed9e4118e131392 Mon Sep 17 00:00:00 2001 From: mr-melos <1595862940@qq.com> Date: Wed, 10 Aug 2022 17:06:00 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contrib/cv/detection/GFocalV2/README.md | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index 6334dbecc4..65cf695a90 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -199,6 +199,14 @@ python3.7 gfocal_postprocess.py --bin_data_path=./out/2* --test_annotation=gfoca ``` 参数"--bin_data_path"为推理生成结果文件的路径。 执行完后会打印出精度。 +``` +Average Precision(AP)@[ IoU=0.50:0.95 | area=all | maxDets=100 ] =0.406 +``` +[官网精度](https://github.com/implus/GFocalV2) +``` +Average Precision(AP)@[ IoU=0.50:0.95 | area=all | maxDets=100 ] =0.410 +``` + ## 7 性能对比 - **[310性能数据](#71-310性能数据)** @@ -237,14 +245,17 @@ Inference average time without first time : 28.99ms 计算fps时使用1000/28.99=34.49fps ### 7.3 性能对比 -``` - **评测结果:** -| 模型 | 在线推理精度 | 310P离线推理精度 | 310P性能 | 310性能 |T4性能 | -| :------: | :------: | :------: | :------: | :------: | :------: | -| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 34.49fps | 17.92fps | 9.4fps | +**评测结果:** + +| 模型 | 310P性能 | 310性能 |T4性能 |310P/310 |310P/T4| +| :------: | :------: | :------: | :------: |:------: | :------: | +| GFocalV2 bs1 | 34.49fps |17.92fps | 9.4fps |1.92| 3.67| + +``` # 710性能是否超过基准: 是 310P vs 310: bs1:710=(34.49/17.92) 1.92倍基准 310P vs T4: bs1:710=(34.49/9.4) 3.67倍基准 性能在310P上的性能超过310的1.2倍,超过T4性能的1.6倍,性能达标 -备注:离线模型不支持多batch。 \ No newline at end of file +备注:离线模型不支持多batch。 +``` \ No newline at end of file -- Gitee