已合并
GENet模型整改 #2800
shikang2022创建于 2022年11月30日
GENet模型整改 #2800
已合并
shikang2022创建于 2022年11月30日
GENet合入到master
10 个文件变更+267-347
RACL_PyTorch/contrib/cv/classfication/GENet/cifar10_acc_eval.pyACL_PyTorch/contrib/cv/classfication/GENet/GENet_postprocess.py+0-0
文件重命名但无更改。
RACL_PyTorch/contrib/cv/classfication/GENet/preprocess.pyACL_PyTorch/contrib/cv/classfication/GENet/GENet_preprocess.py+0-0
文件重命名但无更改。
RACL_PyTorch/contrib/cv/classfication/GENet/pthtar2onnx.pyACL_PyTorch/contrib/cv/classfication/GENet/GENet_pth2onnx.py+13-0
@@ -1,3 +1,16 @@
1+# Copyright 2021 Huawei Technologies Co., Ltd
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
1import torch14import torch
2import torch.onnx15import torch.onnx
3from collections import OrderedDict16from collections import OrderedDict
@@ -1,161 +1,256 @@
1-## <a name="1">1. 模型概述</a>1+# GENet模型-推理指导
2-### 1.1 参考论文
3-[GENet论文](https://arxiv.org/abs/1810.12348)
4-### 1.2 参考实现
5-[代码地址](https://github.com/BayesWatch/pytorch-GENet)
6-> branch: master
7- 
8-> commit id: 3fbf99fb6934186004ffb5ea5c0732e0e976d5b2
9- 
10-## <a name="1">2. 推理环境准备</a>
11-### 2.1 环境介绍
12-CANN=[5.0.4](https://www.hiascend.com/software/cann/commercial?version=5.0.4)。
13-硬件环境、开发环境和运行环境准备请参见[CANN 软件安装指南](https://www.hiascend.com/document/detail/zh/canncommercial/504/envdeployment/instg)。
14-### 2.2 所需依赖
15-```
16-Pytorch>=1.5.0
17-Torchvision>=0.6.0
18-ONNX>=1.7.0
19-numpy==1.18.5
20-Pillow==7.2.0
21-```
22-### 2.3 环境配置
23-```
24-pip3.7 install -r requirements.txt
25-```
26-## <a name="1">3. 数据集准备</a>
27-### 3.1 下载数据集
28-在官方下载cifar10数据集
29-### 3.2 数据预处理
30-准备Bin文件
31-```
32-python3.7 preprocess.py ${datasets_path} ./prep_dataset
33-```
34-第一个参数为数据集存放目录(例:若数据集路径为/home/HwHiAiUser/dataset/cifar-10-batches-py/,则数据集存放目录为/home/HwHiAiUser/dataset/),第二个参数为预处理后的数据文件的相对路径。该操作会在数据文件的目录下生成标签文件val_label.txt。
35-### 3.3 生成数据集info文件
36-```
37-python3.7 get_info.py bin ./prep_dataset ./genet_prep_bin.info 32 32
38-```
39-第一个参数为生成的数据集文件格式,第二个参数为预处理后的数据文件的相对路径,第三个参数为生成的数据集文件保存的路径。运行成功后,在当前目录中生成genet_prep_bin.info。
40-## <a name="1">4. 模型转换</a>
41-### 4.1 获取源码
42-```
43-git clone https://github.com/BayesWatch/pytorch-GENet.git
44-cd pytorch-GENet/
45-git reset 3fbf99fb6934186004ffb5ea5c0732e0e976d5b2 --hard
46-cd ../
47-```
48-### 4.2 pth转onnx模型
49-```
50-python3.7 pthtar2onnx.py ${model_path}
51-```
52-其中${model_path}指的是模型路径,如/home/HwHiAiUser/model/genet.pth.tar
53-### 4.3 onnx转om模型
54-设置环境变量
55-```
56-source /usr/local/Ascend/ascend-toolkit/set_env.sh
57-```
58-使用ATC工具转换,工具使用方法可以参考[《CANN 开发辅助工具指南 (推理)》](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)
59- 
60-${chip_name}可通过`npu-smi info`指令查看
61- 
62- ![Image](https://gitee.com/ascend/ModelZoo-PyTorch/raw/master/ACL_PyTorch/images/310P3.png)
63-
64-```
65-bash test/onnx2om.sh Ascend${chip_name} # Ascend310P3
66-```
67-该指令会生成genet_bs16_tuned,genet_bs1_tuned两个模型,可在onnx2om.sh文件中修改以生成不同bs值的om模型
68-> **说明**
69-> 注意目前ATC支持的onnx算子版本为11
70-## <a name="1">5. 推理验证</a>
71-### 5.1 使用指南
72-[《CANN 推理benchmark工具用户指南》](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)
73-### 5.2 离线推理
74-1.增加benchmark.{arch}可执行权限
75-```
76-chmod u+x benchmark.x86_64
77-```
78-2.推理
79-```
80-bash test/infer_bin.sh
81-```
82-可以通过修改batch_size的值进行在不同batchsize情况下的推理(同时要修改对应的om文件路径即om_path的值)。运行该指令后输出结果默认保存在当前目录/result/dumpOutput_device0中,同时在/result目录下会生成一个推理性能文件
83- 
84-3.获取性能信息
85-```
86-python3.7 test/parse.py result/perf_vision_batchsize_1_device_0.txt
87-```
88-运行该指令获得bs为1时推理所得的310的性能信息,实例如下:
89-```
90-[e2e] throughputRate: 132.777, latency: 75314.4
91-[data read] throughputRate: 134.331, moduleLatency: 7.44429
92-[preprocess] throughputRate: 134.114, moduleLatency: 7.45634
93-[inference] throughputRate: 134.244, Interface throughputRate: 809.813, moduleLatency: 1.35099
94-[postprocess] throughputRate: 134.257, moduleLatency: 7.44838
95-```
96-4,gpu设备的推理
97-将onnx模型置于装有gpu的设备,参考以下指令获取onnx模型在gpu上推理的性能信息
98-```
99-bash test/perf_g.sh
100-```
101-## <a name="1">6. 精度验证</a>
102-1.参考以下指令生成精度信息文件
103-```
104-python3.7 cifar10_acc_eval.py result/dumpOutput_device0/ ./prep_dataset/val_label.txt ./ result_bs1.json
105-```
106-第一个参数为生成推理结果所在路径,第二个参数为标签数据,第三个参数为生成结果文件路径,第四个参数为生成结果文件名
107- 
108-2.参考以下指令获取310上推理的精度信息
109-```
110-python3.7 test/parse.py result_bs1.json
111-```
112-精度参考:
113-| GENET模型| gpu吞吐率| 310吞吐率 | 精度|
114-|--|--|--|--|
115-| bs1| 1805.315fps| 3239.252fps|Error@1 5.78 Error@5 0.15|
116-| bs16| 5922.109fps| 7796.88fps|Error@1 5.78 Error@5 0.15 |
117 2 
118 3 
119-## <a name="7">7. 性能对比</a>4+- [概述](#ZH-CN_TOPIC_0000001172161501)
120-测试时要保证设备空闲,npu-smi info可以查看设备状态。benchmark工具在整个数据集上推理方式测性能可能时间较长,纯推理方式测性能可能不准确,因此bs1与bs16要使用在整个数据集上推理的方式测性能,bs4、8、32可以用纯推理的方式测性能。benchmark工具测的Interface throughputRate或samples/s数据是单个device吞吐率,计算310单卡吞吐率需要乘以4。tensorrt工具测的t4数据GPU Compute的mean代表batch个数据的时延,1000/(GPU Compute mean/batch)可以将其转换为吞吐率。 5+ 
121-### 7.1 310性能数据6+ - [输入输出数据](#section540883920406)
122-以310的bs1为例:7+ 
123-```8+ 
124-[e2e] throughputRate: 132.777, latency: 75314.49+ 
125-[data read] throughputRate: 134.331, moduleLatency: 7.4442910+- [推理环境准备](#ZH-CN_TOPIC_0000001126281702)
126-[preprocess] throughputRate: 134.114, moduleLatency: 7.4563411+ 
127-[inference] throughputRate: 134.244, Interface throughputRate: 809.813, moduleLatency: 1.3509912+- [快速上手](#ZH-CN_TOPIC_0000001126281700)
128-[postprocess] throughputRate: 134.257, moduleLatency: 7.4483813+ 
129-```14+ - [获取源码](#section4622531142816)
130-Interface throughputRate: 809.813,809.813x4=3239.252 fps。即是batch1 310单卡吞吐率,batch16的计算方法同理15+ - [准备数据集](#section183221994411)
131-> 为了避免长期占用device, bs4,8,32使用纯推理测性能,其中,对bs4进行纯推理输入命令如下所示,其中batch_size=4表示bs的值,在对不同bs值对应的om模型进行推理时需要做出相应的更改:16+ - [模型推理](#section741711594517)
132-> `./benchmark.x86_64 -device_id=0 -om_path=genet_bs4_tuned.om -round=30 -batch_size=4`17+ 
133-> 18+- [模型推理性能&精度](#ZH-CN_TOPIC_0000001172201573)
134-计算bs4,8,32的吞吐率时,计算方法也同样为Interface throughputRate乘419+ 
135-### 7.2 310P性能数据20+ 
136-310P的推理过程与310相似,可以参考前面310的步骤。不同的是310P的吞吐率即为Interface throughputRate的值,无需乘421+ 
137-### 7.3 T4性能数据22+# 概述<a name="ZH-CN_TOPIC_0000001172161501"></a>
138-在运行5.2的gpu推理指令时,我们会获得相关的性能信息,以T4的bs1为例:23+ 
139-```24+作者在大量实验研究的基础上提出了一种GPU端高效网络设计的通用范式,该设计范式促使作者仅需要采用简单而轻量的NAS方法即可得到高效且高精度的GPU端网络架构。基于所设计的网络架构设计范式,作者提出了一类GPU端高效的网络,称之为GENet。
140-[05/13/2022-16:53:32] 25+ 
141-[I] GPU Compute Time: 26+- 参考实现:
142-min = 0.512207 ms, 27+ 
143-max = 2.97815 ms, 28+ ```
144-mean = 0.55392 ms, 29+ url=git clone https://github.com/BayesWatch/pytorch-GENet.git
145-median = 0.540283 ms,30+ commit_id=3fbf99fb6934186004ffb5ea5c0732e0e976d5b2
146-percentile(99%) = 0.690048 ms31+ model_name=pytorch-GENet
147-```32+ ```
148-batch1 t4单卡吞吐率:1000/(0.55392/1)=1805.315 fps 33+ 
149-计算方法为1000/(GPU Compute mean/batch)34+## 输入输出数据<a name="section540883920406"></a>
150-### 7.4 性能对比35+ 
151-性能对比结果参考如下:36+- 输入数据
152-| | 310 | 310P | T4 | 310P/310 | 310P/T4 |37+ 
153-|---------|----------|---------|----------|-------------|-------------|38+ | 输入数据 | 数据类型 | 大小 | 数据排布格式 |
154-| bs1 | 3239.252 | 2580.59 | 1805.315 | 0.796662316 | 1.429440292 |39+ | -------- | -------- | ------------------------- | ------------ |
155-| bs4 | 6923.88 | 6962.42 | 3258.019 | 1.005566243 | 2.137010251 |40+ | input | RGB_FP32 | batchsize x 3 x 32 x 32 | NCHW |
156-| bs8 | 6631 | 9350.57 | 5226.538 | 1.410129694 | 1.789056159 |41+ 
157-| bs16 | 7796.88 | 10586.7 | 5922.109 | 1.357812356 | 1.787657066 |42+ 
158-| bs32 | 7295.48 | 11005.9 | 5898.248 | 1.508591621 | 1.865960875 |43+- 输出数据
159-| bs64 | 6611.72 | 11256.5 | 6105.938 | 1.702507063 | 1.843533295 |44+ 
160-| 最优batch | 7796.88 | 11256.5 | 6105.938 | 1.443718513 | 1.843533295 |45+ | 输出数据 | 数据类型 | 大小 | 数据排布格式 |
161-取310、310P与T4的最优batch进行对比,当310P的最优batch性能不低于310最优batch的1.2倍以及T4最优batch的1.6倍时,性能达标46+ | -------- | -------- | -------- | ------------ |
47+ | output1 | FLOAT32 | 1 x 1000 | ND |
48+ 
49+ 
50+ 
51+# 推理环境准备<a name="ZH-CN_TOPIC_0000001126281702"></a>
52+ 
53+- 该模型需要以下插件与驱动
54+ 
55+ **表 1** 版本配套表
56+ 
57+ | 配套 | 版本 | 环境准备指导 |
58+ | ------------------------------------------------------------ | ------- | ------------------------------------------------------------ |
59+ | 固件与驱动 | 22.0.2 | [Pytorch框架推理环境准备](https://www.hiascend.com/document/detail/zh/ModelZoo/pytorchframework/pies) |
60+ | CANN | 6.0.RC1 | - |
61+ | Python | 3.7.5 | - |
62+ | PyTorch | 1.5.0 | - |
63+ | 说明:Atlas 300I Duo 推理卡请以CANN版本选择实际固件与驱动版本。 | \ | \ |
64+ 
65+ 
66+ 
67+# 快速上手<a name="ZH-CN_TOPIC_0000001126281700"></a>
68+ 
69+## 获取源码<a name="section4622531142816"></a>
70+ 
71+1. 获取源码。
72+ 
73+ ```
74+ git clone https://github.com/BayesWatch/pytorch-GENet.git
75+ cd pytorch-GENet/
76+ git reset --hard 3fbf99fb6934186004ffb5ea5c0732e0e976d5b2
77+ cd ..
78+ ```
79+ 
80+2. 安装依赖。
81+ 
82+ ```
83+ pip install -r requirements.txt
84+ ```
85+ 
86+## 准备数据集<a name="section183221994411"></a>
87+ 
88+1. 获取原始数据集。(解压命令参考tar –xvf \*.tar与 unzip \*.zip)
89+ 本模型支持cifar-10验证集。用户需自行获取数据集,将压并上传数据集到当前目录新建文件夹data下。目录结构如下:
90+ 
91+ ```
92+ data
93+ └── cifar-10-batchses-py
94+ ```
95+ 
96+2. 数据预处理,将原始数据集转换为模型输入的数据。
97+ 
98+ 执行GENet_preprocess.py脚本,完成预处理。
99+ 
100+ ```
101+ python GENet_preprocess.py ./data/ ./predata
102+ ```
103+ - 参数说明:
104+ 
105+ - 第一个参数:数据集目录
106+ - 第二个参数:预处理数据保存目录
107+ 
108+ 
109+## 模型推理<a name="section741711594517"></a>
110+ 
111+1. 模型转换。
112+ 
113+ 使用PyTorch将模型权重文件.pth转换为.onnx文件,再使用ATC工具将.onnx文件转为离线推理模型文件.om文件。
114+ 
115+ 1. 获取权重文件。
116+ 
117+ ```
SL
Sshikang20222022年12月26日

当前目录是哪个目录,当前目录下的权重文件来源是哪里

已修改

likedislike
Lliuzhuheng2022年12月8日

当前目录是哪个目录,当前目录下的权重文件来源是哪里

likedislike
118+ wget https://ascend-repo-modelzoo.obs.cn-east-2.myhuaweicloud.com/model/1_PyTorch_PTH/GENET/PTH/genet.pth.tar
119+ ```
120+ 
121+ 2. 导出onnx文件。
122+ 
123+ 1. 使用GENet_pth2onnx.py导出onnx文件。
124+ 
125+ 运行GENet_pth2onnx.py脚本。
126+ 
127+ ```
128+ python GENet_pth2onnx.py genet.pth.tar genet.onnx
129+ ```
130+ - 参数说明:
131+ 
132+ - 第一个参数:权重文件
133+ - 第二个参数:保存onnx文件
134+ 
135+ 获得genet.onnx文件。
136+ 
137+ 
138+ 3. 使用ATC工具将ONNX模型转OM模型。
139+ 
140+ 1. 配置环境变量。
141+ 
142+ ```
143+ source /usr/local/Ascend/ascend-toolkit/set_env.sh
144+ ```
145+ 
146+ 2. 执行命令查看芯片名称($\{chip\_name\})。
147+ 
148+ ```
149+ npu-smi info
150+ #该设备芯片名为Ascend310P3 (自行替换)
151+ 回显如下:
152+ +-------------------+-----------------+------------------------------------------------------+
153+ | NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
154+ | Chip Device | Bus-Id | AICore(%) Memory-Usage(MB) |
155+ +===================+=================+======================================================+
156+ | 0 310P3 | OK | 15.8 42 0 / 0 |
157+ | 0 0 | 0000:82:00.0 | 0 1074 / 21534 |
158+ +===================+=================+======================================================+
159+ | 1 310P3 | OK | 15.4 43 0 / 0 |
160+ | 0 1 | 0000:89:00.0 | 0 1070 / 21534 |
161+ +===================+=================+======================================================+
162+ ```
163+ 
164+ 3. 执行ATC命令。
165+ 
166+ ```
167+ atc --model=genet.onnx \
168+ --framework=5 \
169+ --input_format=NCHW \
170+ --input_shape="image:${bs},3,32,32" \
171+ --output=genet_bs${bs} \
172+ --soc_version= Ascend${chip_name}
173+ ```
174+ 
175+ - 参数说明:
176+ 
177+ - --model:为ONNX模型文件。
178+ - --framework:5代表ONNX模型。
179+ - --output:输出的OM模型。
180+ - --input\_format:输入数据的格式。
181+ - --input\_shape:输入数据的shape。
182+ - --log:日志级别。
183+ - --soc\_version:处理器型号
184+ 
185+ 运行成功后生成<u>***genet_bs${bs}.om***</u>模型文件。
186+ 
187+2. 开始推理验证。
188+ 
189+ 1. 使用ais-infer工具进行推理。
190+ 
191+ ais-infer工具获取及使用方式请点击查看[[ais_infer 推理工具使用文档](https://gitee.com/ascend/tools/tree/master/ais-bench_workload/tool/ais_infer)]
192+ 
193+ 2. 执行推理。
194+ 
195+ ```
196+ python ${ais_infer_path}/ais_infer.py --model=genet_bs${bs} --input=./predata --output=./ --output_dirname=./result --batchsize=${batch_size} --outfmt=TXT
197+ ```
198+ 
199+ - 参数说明:
200+ 
201+ - model:om模型地址
202+ - input:预处理数据
203+ - output:推理结果保存路径
204+ - output_dirname:推理结果保存子目录
205+ - outfmt:输出数据格式
206+ 
207+ 
208+ 推理后的输出保存在当前目录result下。
209+ 
210+ >**说明:**
211+ >执行ais-infer工具请选择与运行环境架构相同的命令。参数详情请参见。
212+ 
213+ 3. 精度验证。
214+ 
215+ 调用脚本与数据集标签val\_label.txt比对,可以获得Accuracy数据,结果保存在result.json中。
216+ 
217+ ```
218+ python3 GENet_postprocess.py ./result/ ./predata/val_label.txt ./ result.json
219+ ```
220+ 
221+ - 参数说明:
222+ 
223+ - result:为生成推理结果所在路径
224+ 
225+ 
226+ - val_label.txt:为标签数据
227+ 
228+ 
229+ - result.json:为生成结果文件
230+ 
231+ 4. 性能验证。
232+ 
233+ 可使用ais_infer推理工具的纯推理模式验证不同batch_size的om模型的性能,参考命令如下:
234+ 
235+ ```
236+ python3.7 ${ais_infer_path}/ais_infer.py --model=genet_bs${bs}.om --loop=100 --batchsize=${batch_size}
237+ ```
238+ 
239+ - 参数说明:
240+ - --model:om模型路径
241+ - --batchsize:batchsize大小
242+ 
243+ 
244+ 
245+# 模型推理性能&精度<a name="ZH-CN_TOPIC_0000001172201573"></a>
246+ 
247+调用ACL接口推理计算,性能参考下列数据。
248+ 
249+| 芯片型号 | Batch Size | 数据集 | 精度 | 性能 |
250+| --------- | ---------------- | ---------- | ---------- | --------------- |
251+| Ascend310P3 | 1 | cifar-10 | top1:94.23% | 2652 |
252+| Ascend310P3 | 4 | cifar-10 | top1:94.23% | 6981 |
253+| Ascend310P3 | 8 | cifar-10 | top1:94.23% | 7768 |
254+| Ascend310P3 | 16 | cifar-10 | top1:94.23% | 9981 |
255+| Ascend310P3 | 32 | cifar-10 | top1:94.23% | 7991 |
256+| Ascend310P3 | 64 | cifar-10 | top1:94.23% | 9235 |
@@ -1,58 +0,0 @@
1-# Copyright 2021 Huawei Technologies Co., Ltd
2-#
3-# Licensed under the Apache License, Version 2.0 (the "License");
4-# you may not use this file except in compliance with the License.
5-# You may obtain a copy of the License at
6-#
7-# http://www.apache.org/licenses/LICENSE-2.0
8-#
9-# Unless required by applicable law or agreed to in writing, software
10-# distributed under the License is distributed on an "AS IS" BASIS,
11-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-# See the License for the specific language governing permissions and
13-# limitations under the License.
14-# ============================================================================
15- 
16-import os
17-import sys
18-from glob import glob
19- 
20-def get_bin_info(file_path, info_name, width, height):
21- bin_images = glob(os.path.join(file_path, '*.bin'))
22- bin_images.sort()
23- with open(info_name, 'w') as file:
24- for index, img in enumerate(bin_images):
25- content = ' '.join([str(index), img, width, height])
26- file.write(content)
27- file.write('\n')
28-
29-def get_jpg_info(file_path, info_name):
30- extensions = ['jpg', 'jpeg', 'JPG', 'JPEG']
31- image_names = []
32- for extension in extensions:
33- image_names.append(glob(os.path.join(file_path, '*.' + extension)))
34- with open(info_name, 'w') as file:
35- for image_name in image_names:
36- if len(image_name) == 0:
37- continue
38- else:
39- for index, img in enumerate(image_name):
40- img_cv = cv2.imread(img)
41- shape = img_cv.shape
42- width, height = shape[1], shape[0]
43- content = ' '.join([str(index), img, str(width), str(height)])
44- file.write(content)
45- file.write('\n')
46- 
47-if __name__ == '__main__':
48- file_type = sys.argv[1]
49- file_path = sys.argv[2]
50- info_name = sys.argv[3]
51- if file_type == 'bin':
52- width = sys.argv[4]
53- height = sys.argv[5]
54- assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5'
55- get_bin_info(file_path, info_name, width, height)
56- elif file_type == 'jpg':
57- assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3'
58- get_jpg_info(file_path, info_name)
@@ -1,71 +0,0 @@
1-#!/bin/bash
2- 
3-datasets_path="/opt/npu/"
4- 
5-for para in $*
6-do
7- if [[ $para == --datasets_path* ]]; then
8- datasets_path=`echo ${para#*=}`
9- fi
10-done
11- 
12-source /usr/local/Ascend/ascend-toolkit/set_env.sh
13- 
14-arch=`uname -m`
15-rm -rf ./prep_dataset
16-python3.7 preprocess.py genet ${datasets_path} ./prep_dataset
17-if [ $? != 0 ]; then
18- echo "fail!"
19- exit -1
20-fi
21-python3.7 get_info.py bin ./prep_dataset ./genet_prep_bin.info 32 32
22-if [ $? != 0 ]; then
23- echo "fail!"
24- exit -1
25-fi
26- 
27-rm -rf result/dumpOutput_device0
28-./benchmark.${arch} -model_type=vision -device_id=0 -batch_size=1 -om_path=genet_bs1_tuned.om -input_text_path=./genet_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False
29-if [ $? != 0 ]; then
30- echo "fail!"
31- exit -1
32-fi
33-rm -rf result/dumpOutput_device1
34-./benchmark.${arch} -model_type=vision -device_id=1 -batch_size=16 -om_path=genet_bs16_tuned.om -input_text_path=./genet_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False
35-if [ $? != 0 ]; then
36- echo "fail!"
37- exit -1
38-fi
39-python3.7 cifar10_acc_eval.py result/dumpOutput_device0/ ./prep_dataset/val_label.txt ./ result_bs1.json
40-if [ $? != 0 ]; then
41- echo "fail!"
42- exit -1
43-fi
44-python3.7 cifar10_acc_eval.py result/dumpOutput_device0/ ./prep_dataset/val_label.txt ./ result_bs16.json
45-if [ $? != 0 ]; then
46- echo "fail!"
47- exit -1
48-fi
49-echo "====accuracy data===="
50-python3.7 test/parse.py result_bs1.json
51-if [ $? != 0 ]; then
52- echo "fail!"
53- exit -1
54-fi
55-python3.7 test/parse.py result_bs16.json
56-if [ $? != 0 ]; then
57- echo "fail!"
58- exit -1
59-fi
60-echo "====performance data===="
61-python3.7 test/parse.py result/perf_vision_batchsize_1_device_0.txt
62-if [ $? != 0 ]; then
63- echo "fail!"
64- exit -1
65-fi
66-python3.7 test/parse.py result/perf_vision_batchsize_16_device_1.txt
67-if [ $? != 0 ]; then
68- echo "fail!"
69- exit -1
70-fi
71-echo "success"
@@ -1,2 +0,0 @@
1-benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=genet_bs1_tuned.om -input_text_path=genet_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False
2-benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=genet_bs16_tuned.om -input_text_path=genet_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False
@@ -1,4 +0,0 @@
1-source /usr/local/Ascend/ascend-toolkit/set_env.sh
2- 
3-atc --model=genet_gpu.onnx --framework=5 --input_format=NCHW --input_shape="image:1,3,32,32" --output=genet_bs1_tuned --soc_version=$1 --auto_tune_mode="GA" --log=debug
4-atc --model=genet_gpu.onnx --framework=5 --input_format=NCHW --input_shape="image:16,3,32,32" --output=genet_bs16_tuned --soc_version=$1 --auto_tune_mode="GA" --log=debug
@@ -1,33 +0,0 @@
1-# Copyright 2021 Huawei Technologies Co., Ltd
2-#
3-# Licensed under the Apache License, Version 2.0 (the "License");
4-# you may not use this file except in compliance with the License.
5-# You may obtain a copy of the License at
6-#
7-# http://www.apache.org/licenses/LICENSE-2.0
8-#
9-# Unless required by applicable law or agreed to in writing, software
10-# distributed under the License is distributed on an "AS IS" BASIS,
11-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-# See the License for the specific language governing permissions and
13-# limitations under the License.
14- 
15-import sys
16-import json
17-import re
18- 
19-if __name__ == '__main__':
20- if sys.argv[1].endswith('.json'):
21- result_json = sys.argv[1]
22- with open(result_json, 'r') as f:
23- content = f.read()
24- #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')]
25- #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4]))
26- print(content)
27- elif sys.argv[1].endswith('.txt'):
28- result_txt = sys.argv[1]
29- with open(result_txt, 'r') as f:
30- content = f.read()
31- txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')]
32- fps = float(txt_data_list[7].replace('samples/s', '')) * 4
33- print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps))
@@ -1,20 +0,0 @@
1-#!/bin/bash
2-trtexec --onnx=genet_gpu.onnx --fp16 --shapes=image:1x3x32x32 --threads > genet_bs1.log
3-perf_str=`grep "GPU.* mean.*ms$" genet_bs1.log`
4-if [ -n "$perf_str" ]; then
5- perf_num=`echo $perf_str | awk -F' ' '{print $16}'`
6-else
7- perf_str=`grep "mean.*ms$" genet_bs1.log`
8- perf_num=`echo $perf_str | awk -F' ' '{print $4}'`
9-fi
10-awk 'BEGIN{printf "gpu bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}'
11- 
12-trtexec --onnx=genet_gpu.onnx --fp16 --shapes=image:16x3x32x32 --threads > genet_bs16.log
13-perf_str=`grep "GPU.* mean.*ms$" genet_bs16.log`
14-if [ -n "$perf_str" ]; then
15- perf_num=`echo $perf_str | awk -F' ' '{print $16}'`
16-else
17- perf_str=`grep "mean.*ms$" genet_bs16.log`
18- perf_num=`echo $perf_str | awk -F' ' '{print $4}'`
19-fi
20-awk 'BEGIN{printf "gpu bs16 fps:%.3f\n", 1000*1/('$perf_num'/16)}'