diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNeXt50_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNeXt50_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNeXt50_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNeXt50_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/LICENSE" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/LICENSE" new file mode 100644 index 0000000000000000000000000000000000000000..eeac88fb9dc15a1427b41173cf5f136327230c49 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/LICENSE" @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/README.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..a37c7038bb37a6b948a1aa8ea7f508c8f5e1960d --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/README.md" @@ -0,0 +1,345 @@ +# ResNeXt50 Onnx模型端到端推理指导 +- [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 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理精度统计](#61-离线推理精度统计) + - [6.2 开源精度](#62-开源精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + - [7.2 T4性能数据](#72-T4性能数据) + - [7.3 性能对比](#73-性能对比) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[ResNeXt50论文](https://arxiv.org/abs/1611.05431) + +### 1.2 代码地址 +[ResNeXt50代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) +branch:master +commit id:b68adcf9a9280aef02fc08daed170d74d0892361 +$\color{red}{说明:删除线用于说明READ.md必要的包含项,以下带有删除线的说明在README.md中需要删除}$ +~~优先使用本任务提供的开源代码仓,填写分支与commit id,需要从github的commits中找到commit id,commit id是指基于该次提交时的模型代码做推理,通常选择稳定版本的最后一次提交,或代码仓最新的一次提交~~ + + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +python3.7.5 +CANN 5.0.1 + +pytorch >= 1.5.0 +torchvision >= 0.6.0 +onnx >= 1.7.0 +``` +~~目前推理310服务器安装的是蓝区商用版本CANN 5.0.1,库若无特殊版本要求以上三个库固定这么写,需要使用python3.7命令执行脚本,pip3.7命令安装库,torch使用1.5.0版本,如果开源模型代码导出onnx要求torch版本大于1.5.0,则使用1.8.0版本,并在此处说明~~ + +### 2.2 python第三方库 + +``` +numpy == 1.20.3 +Pillow == 8.2.0 +opencv-python == 4.5.2.54 +``` +~~requirements.txt中需要写明本模型离线推理所有必要依赖库的具体版本,版本号即是推理310服务器上推理时使用库的版本号~~ + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[ResNeXt50预训练pth权重文件](https://download.pytorch.org/models/resnext50_32x4d-7cdf4587.pth) +文件md5sum: 1d6611049e6ef03f1d6afa11f6f9023e +``` +wget https://download.pytorch.org/models/resnext50_32x4d-7cdf4587.pth +``` +~~优先使用训练提供的权重文件,如果训练的权重文件网上能获则需给出网址,否则需要给出从哪获取权重文件。如果训练没有提供权重则使用开源代码仓的权重文件。需要给出权重文件名与通过md5sum命令计算的权重文件md5sum值~~ +2.resnext50模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 +``` +git clone https://github.com/pytorch/vision +cd vision +git reset b68adcf9a9280aef02fc08daed170d74d0892361 --hard +python3.7 setup.py install +cd .. +``` +~~如果需要对模型的开源代码做修改,以打patch的形式修改后再安装:patch -p1 < ../{patch_name}.diff~~ +3.编写pth2onnx脚本resnext50_pth2onnx.py +~~如果模型开源代码仓没有安装脚本,可以通过sys.path.append(r"./vision")添加搜索路径,然后就可以引用模型开源代码仓的函数或类~~ + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 resnext50_pth2onnx.py resnext50_32x4d-7cdf4587.pth resnext50.onnx +``` + + **模型转换要点:** +~~对于CANN包算子有问题导致模型转换失败或需要规避才能转换成功,则需要在模型转换要点里写明定位主要过程,原因与措施~~ +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 +``` +atc --framework=5 --model=./resnext50.onnx --input_format=NCHW --input_shape="image:16,3,224,224" --output=resnext50_bs16 --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnext50_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=resnext50_bs16.om -input_text_path=./resnext50_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理精度](#61-离线推理精度)** +- **[开源精度](#62-开源精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "77.62%"}, {"key": "Top2 accuracy", "value": "87.42%"}, {"key": "Top3 accuracy", "value": "90.79%"}, {"key": "Top4 accuracy", "value": "92.56%"}, {"key": "Top5 accuracy", "value": "93.69%"}] +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 +~~因为batch可能影响精度,如果模型支持多batch的话,精度测试需要且仅测试bs1与bs16的精度~~ + +### 6.2 开源精度 +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) +``` +Model Acc@1 Acc@5 +ResNeXt-50-32x4d 77.618 93.698 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +~~对于CANN包算子有问题导致精度不达标或需要规避才能达标,则需要在精度调试里写明定位主要过程,原因与措施~~ +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** +- **[T4性能数据](#72-T4性能数据)** +- **[性能对比](#73-性能对比)** + +~~性能数据需要测bs1,16,4,8,32的性能数据,且需要计算出单卡吞吐率。对于npu,bs1,16要在整个数据集上推理测性能,为了避免长期占用device,bs4,8,32也可以使用纯推理测性能~~ + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 243.034, latency: 205733 +[data read] throughputRate: 258.963, moduleLatency: 3.86155 +[preprocess] throughputRate: 258.404, moduleLatency: 3.86991 +[infer] throughputRate: 244.435, Interface throughputRate: 382.328, moduleLatency: 3.35758 +[post] throughputRate: 244.435, moduleLatency: 4.09107 +``` +Interface throughputRate: 382.328,382.328x4=1529.312既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 173.173, latency: 288729 +[data read] throughputRate: 174.62, moduleLatency: 5.72673 +[preprocess] throughputRate: 174.357, moduleLatency: 5.73535 +[infer] throughputRate: 173.844, Interface throughputRate: 519.634, moduleLatency: 3.36724 +[post] throughputRate: 10.865, moduleLatency: 92.0383 +``` +Interface throughputRate: 519.634,519.634x4=2078.536既是batch16 310单卡吞吐率 +batch4性能: +``` +[e2e] throughputRate: 232.98, latency: 214611 +[data read] throughputRate: 235.537, moduleLatency: 4.24562 +[preprocess] throughputRate: 235.147, moduleLatency: 4.25266 +[infer] throughputRate: 234.437, Interface throughputRate: 492.99, moduleLatency: 3.48397 +[post] throughputRate: 58.6087, moduleLatency: 17.0623 +``` +batch4 310单卡吞吐率:492.99x4=1971.96fps +batch8性能: +``` +[e2e] throughputRate: 211.307, latency: 236622 +[data read] throughputRate: 212.246, moduleLatency: 4.71152 +[preprocess] throughputRate: 211.931, moduleLatency: 4.71851 +[infer] throughputRate: 211.927, Interface throughputRate: 496.378, moduleLatency: 3.45797 +[post] throughputRate: 26.4906, moduleLatency: 37.7493 +``` +batch8 310单卡吞吐率:496.378x4=1985.512fps +batch32性能: +``` +[e2e] throughputRate: 122.942, latency: 406696 +[data read] throughputRate: 123.244, moduleLatency: 8.11402 +[preprocess] throughputRate: 123.143, moduleLatency: 8.12064 +[infer] throughputRate: 123.207, Interface throughputRate: 377.787, moduleLatency: 4.10655 +[post] throughputRate: 3.8514, moduleLatency: 259.646 +``` +batch32 310单卡吞吐率:377.787x4=1511.148fps + +### 7.2 T4性能数据 +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 +~~目前T4服务器安装的cuda,cudnn,TensorRT版本如上~~ +batch1性能: +``` +trtexec --onnx=resnext50.onnx --fp16 --shapes=image:1x3x224x224 --threads +``` +gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch。其中--fp16是算子精度,目前算子精度只测--fp16的。注意--shapes是onnx的输入节点名与shape,当onnx输入节点的batch为-1时,可以用同一个onnx文件测不同batch的性能,否则用固定batch的onnx测不同batch的性能不准 +``` +[03/24/2021-03:54:47] [I] GPU Compute +[03/24/2021-03:54:47] [I] min: 1.26575 ms +[03/24/2021-03:54:47] [I] max: 4.41528 ms +[03/24/2021-03:54:47] [I] mean: 1.31054 ms +[03/24/2021-03:54:47] [I] median: 1.30151 ms +[03/24/2021-03:54:47] [I] percentile: 1.40723 ms at 99% +[03/24/2021-03:54:47] [I] total compute time: 2.9972 s +``` +batch1 t4单卡吞吐率:1000/(1.31054/1)=763.044fps + +batch16性能: +``` +trtexec --onnx=resnext50.onnx --fp16 --shapes=image:16x3x224x224 --threads +``` +``` +[03/24/2021-03:57:22] [I] GPU Compute +[03/24/2021-03:57:22] [I] min: 12.5645 ms +[03/24/2021-03:57:22] [I] max: 14.8437 ms +[03/24/2021-03:57:22] [I] mean: 12.9561 ms +[03/24/2021-03:57:22] [I] median: 12.8541 ms +[03/24/2021-03:57:22] [I] percentile: 14.8377 ms at 99% +[03/24/2021-03:57:22] [I] total compute time: 3.03173 s +``` +batch16 t4单卡吞吐率:1000/(12.9561/16)=1234.940fps + +batch4性能: +``` +[05/27/2021-03:16:26] [I] GPU Compute +[05/27/2021-03:16:26] [I] min: 3.77515 ms +[05/27/2021-03:16:26] [I] max: 4.07959 ms +[05/27/2021-03:16:26] [I] mean: 3.92862 ms +[05/27/2021-03:16:26] [I] median: 3.9552 ms +[05/27/2021-03:16:26] [I] percentile: 4.07324 ms at 99% +[05/27/2021-03:16:26] [I] total compute time: 3.0054 s +``` +batch4 t4单卡吞吐率:1000/(3.92862/4)=1018.169fps + +batch8性能: +``` +[05/27/2021-03:14:52] [I] GPU Compute +[05/27/2021-03:14:52] [I] min: 6.52148 ms +[05/27/2021-03:14:52] [I] max: 7.22937 ms +[05/27/2021-03:14:52] [I] mean: 6.80709 ms +[05/27/2021-03:14:52] [I] median: 6.78735 ms +[05/27/2021-03:14:52] [I] percentile: 7.08972 ms at 99% +[05/27/2021-03:14:52] [I] total compute time: 3.01554 s +``` +batch8 t4单卡吞吐率:1000/(6.80709/8)=1175.245fps + +batch32性能: +``` +[05/27/2021-03:13:11] [I] GPU Compute +[05/27/2021-03:13:11] [I] min: 23.126 ms +[05/27/2021-03:13:11] [I] max: 26.0043 ms +[05/27/2021-03:13:11] [I] mean: 24.2826 ms +[05/27/2021-03:13:11] [I] median: 24.2343 ms +[05/27/2021-03:13:11] [I] percentile: 25.6355 ms at 99% +[05/27/2021-03:13:11] [I] total compute time: 3.05961 s +``` +batch32 t4单卡吞吐率:1000/(24.2826/32)=1317.816fps + +### 7.3 性能对比 +batch1:382.328x4 > 1000x1/(1.31054/1) +batch16:519.634x4 > 1000x1/(12.9561/16) +310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率大,故310性能高于T4性能,性能达标。 +对于batch1与batch16,310性能均高于T4性能1.2倍,该模型放在Benchmark/cv/classification目录下。 +~~对比bs1和16,小于1倍放于Research,1-1.2倍放于Official,大于1.2倍放于Benchmark,而实际提交代码时目前都放在Research目录下~~ + **性能优化:** +~~对于CANN包算子有问题导致性能不达标或需要规避才能达标,则需要在性能优化里写明定位主要过程,原因与措施~~ +>没有遇到性能不达标的问题,故不需要进行性能优化 + +~~如果蓝区商用版本测精度或性能不达标,蓝区最新社区CANN版本测可以达标,这里需要写出原因与最新蓝区社区CANN包版本,用最新版本测。如果是无法规避的算子缺陷导致性能不达标,这里需要添加性能不达标的原因与解决方案。如果onnx因包含自定义算子不支持推理,需要说明性能是在t4上测的在线推理,如果模型不支持batch 16,也需要说明一下~~ + + diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/env.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/env.sh" new file mode 100644 index 0000000000000000000000000000000000000000..49be8f16a045f6e4e61666ecc8a5da811c15fd80 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/env.sh" @@ -0,0 +1,8 @@ +#! /bin/bash + +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/gen_dataset_info.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/gen_dataset_info.py" new file mode 100644 index 0000000000000000000000000000000000000000..80c2b0fc300d7037330a166b23c562015cd17148 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/gen_dataset_info.py" @@ -0,0 +1,60 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/imagenet_acc_eval.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/imagenet_acc_eval.py" new file mode 100644 index 0000000000000000000000000000000000000000..0e1db27e816a0cf3ec4fb21ee23e691315f3f959 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/imagenet_acc_eval.py" @@ -0,0 +1,183 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/imagenet_torch_preprocess.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/imagenet_torch_preprocess.py" new file mode 100644 index 0000000000000000000000000000000000000000..65b50a502a600bc3a8ee420cbdbe3c6f13adc02a --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/imagenet_torch_preprocess.py" @@ -0,0 +1,116 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/requirements.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/requirements.txt" new file mode 100644 index 0000000000000000000000000000000000000000..8f0de9561f6cdbfe3facbf31905aee0e9bf7fa9e --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/requirements.txt" @@ -0,0 +1,6 @@ +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +numpy == 1.20.3 +Pillow == 8.2.0 +opencv-python == 4.5.2.54 \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/resnext50_pth2onnx.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/resnext50_pth2onnx.py" new file mode 100644 index 0000000000000000000000000000000000000000..8e180e9245b3f8964b98196e080e3e6e8835077b --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/resnext50_pth2onnx.py" @@ -0,0 +1,35 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models + +def pth2onnx(input_file, output_file): + model = models.resnext50_32x4d(pretrained=False) + checkpoint = torch.load(input_file, map_location=None) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/README.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..c25279493efdab395677a1e991caa2467ca60a11 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/README.md" @@ -0,0 +1,33 @@ +环境准备: + +1.数据集路径 +通用的数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/root/datasets/ + +2.进入工作目录 +cd ResNext50 + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取,修改与安装开源模型代码 +git clone https://github.com/pytorch/vision +cd vision +如果修改了模型代码,交付了{model_name}.diff +patch -p1 < ../{model_name}.diff +如果模型代码需要安装,则安装模型代码(如果没有安装脚本,pth2onnx等脚本需要引用模型代码的类或函数,可通过sys.path.append(r"./vision")添加搜索路径的方式) +python3.7 setup.py install +cd .. + +5.获取权重文件 +wget https://download.pytorch.org/models/resnext50_32x4d-7cdf4587.pth + +6.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放在当前目录 + +7.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets + +8.在t4环境上将onnx文件与perf_t4.sh放在同一目录 +然后执行bash perf_t4.sh,执行时确保gpu空闲 diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/eval_acc_perf.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/eval_acc_perf.sh" new file mode 100644 index 0000000000000000000000000000000000000000..46fcfc68792b801f73d1f214c9fb97a0a0020731 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/eval_acc_perf.sh" @@ -0,0 +1,69 @@ +#!/bin/bash + +datasets_path="/root/datasets/" + +for para in $* +do + if [[ $para == --datasets_path* ]]; then + datasets_path=`echo ${para#*=}` + fi +done + +arch=`uname -m` +rm -rf ./prep_dataset +python3.7 imagenet_torch_preprocess.py resnet ${datasets_path}/imagenet/val ./prep_dataset +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnext50_prep_bin.info 224 224 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +source env.sh +rm -rf result/dumpOutput_device0 +./benchmark.${arch} -model_type=vision -device_id=0 -batch_size=1 -om_path=resnext50_bs1.om -input_text_path=./resnext50_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +rm -rf result/dumpOutput_device1 +./benchmark.${arch} -model_type=vision -device_id=1 -batch_size=16 -om_path=resnext50_bs16.om -input_text_path=./resnext50_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ ${datasets_path}/imagenet/val_label.txt ./ result_bs1.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 imagenet_acc_eval.py result/dumpOutput_device1/ ${datasets_path}/imagenet/val_label.txt ./ result_bs16.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +echo "====accuracy data====" +python3.7 test/parse.py result_bs1.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 test/parse.py result_bs16.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +echo "====performance data====" +python3.7 test/parse.py result/perf_vision_batchsize_1_device_0.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 test/parse.py result/perf_vision_batchsize_16_device_1.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +echo "success" \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/parse.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/parse.py" new file mode 100644 index 0000000000000000000000000000000000000000..b9c74f41d7848e1250356f14472b237a18bb3489 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/parse.py" @@ -0,0 +1,32 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + 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 diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/perf_t4.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/perf_t4.sh" new file mode 100644 index 0000000000000000000000000000000000000000..aee41c4db7a3e56e608c84c89f5cac1d532458d8 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/perf_t4.sh" @@ -0,0 +1,22 @@ +#!/bin/bash + +# T4上执行: +trtexec --onnx=resnext50.onnx --fp16 --shapes=image:1x3x224x224 --threads > resnext50_bs1.log +perf_str=`grep "GPU.* mean.*ms$" resnext50_bs1.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" resnext50_bs1.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' + +trtexec --onnx=resnext50.onnx --fp16 --shapes=image:16x3x224x224 --threads > resnext50_bs16.log +perf_str=`grep "GPU.* mean.*ms$" resnext50_bs16.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" resnext50_bs16.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs16 fps:%.3f\n", 1000*1/('$perf_num'/16)}' \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/pth2om.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/pth2om.sh" new file mode 100644 index 0000000000000000000000000000000000000000..eaf285c653a1a928765ca6c650d557b89e364607 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/ResNext50/test/pth2om.sh" @@ -0,0 +1,13 @@ +#!/bin/bash + +rm -rf resnext50.onnx +python3.7 resnext50_pth2onnx.py resnext50_32x4d-7cdf4587.pth resnext50.onnx +source env.sh +rm -rf resnext50_bs1.om resnext50_bs16.om +atc --framework=5 --model=./resnext50.onnx --input_format=NCHW --input_shape="image:1,3,224,224" --output=resnext50_bs1 --log=debug --soc_version=Ascend310 +atc --framework=5 --model=./resnext50.onnx --input_format=NCHW --input_shape="image:16,3,224,224" --output=resnext50_bs16 --log=debug --soc_version=Ascend310 +if [ -f "resnext50_bs1.om" ] && [ -f "resnext50_bs16.om" ]; then + echo "success" +else + echo "fail!" +fi \ No newline at end of file diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/ssd_detection.diff" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/ssd_detection.diff" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/ssd_detection.diff" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/ssd_detection.diff" diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216detectron2\350\256\255\347\273\203\347\232\204npu\346\235\203\351\207\215\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216detectron2\350\256\255\347\273\203\347\232\204npu\346\235\203\351\207\215\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216detectron2\350\256\255\347\273\203\347\232\204npu\346\235\203\351\207\215\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216detectron2\350\256\255\347\273\203\347\232\204npu\346\235\203\351\207\215\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216\345\274\200\346\272\220mmdetection\351\242\204\350\256\255\347\273\203\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216\345\274\200\346\272\220mmdetection\351\242\204\350\256\255\347\273\203\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216\345\274\200\346\272\220mmdetection\351\242\204\350\256\255\347\273\203\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/\345\237\272\344\272\216\345\274\200\346\272\220mmdetection\351\242\204\350\256\255\347\273\203\347\232\204maskrcnn_Onnx\346\250\241\345\236\213\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" diff --git a/docs/.keep "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/nlp/.keep" similarity index 100% rename from docs/.keep rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/nlp/.keep" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/LICENSE" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/LICENSE" new file mode 100644 index 0000000000000000000000000000000000000000..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/LICENSE" @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/README.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..c5f37d0c9ef5f29c0ff618e9df896b417da223e9 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/README.md" @@ -0,0 +1,53 @@ +$\color{red}{说明:删除线用于READ.md的说明,以下带有删除线的说明在README.md中需要删除}$ + +# ReID-strong-baseline模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` +~~需要使用python3.7命令执行脚本,pip3.7命令安装库,torch使用1.5.0版本,如果开源模型代码导出onnx要求torch版本大于1.5.0,则使用1.8.0版本,并在此处说明。onnx可以选择1.9.0。requirements.txt中需要写明本模型离线推理所有必要依赖库的具体版本,版本号即是推理310服务器上推理时使用库的版本号,常用库包括numpy,Pillow,opencv-python等。目前atc工具支持的onnx算子版本opset_version为11。~~ + + +2.获取,修改与安装开源模型代码 +``` +git clone https://github.com/michuanhaohao/reid-strong-baseline -b master +cd reid-strong-baseline +git reset 3da7e6f03164a92e696cb6da059b1cd771b0346d --hard +cd .. +``` +~~优先使用本任务提供的开源代码仓,并基于分支与commit id的代码做离线推理,分支一般选择master或稳定的版本,需要从github的commits中找到commit id,通常选择稳定版本的最后一次提交,或代码仓最新的一次提交~~ +~~如果需要对模型的开源代码做修改,以打patch的形式修改后再安装:patch -p1 < ../{patch_name}.diff~~ +~~如果开源模型代码仓没有安装脚本,可以通过sys.path.append(r"./reid-strong-baseline")添加搜索路径,然后在pth2onnx脚本中就可以引用模型代码的函数或类~~ + +3.获取权重文件 + +[market_resnet50_model_120_rank1_945.pth](https://drive.google.com/open?id=1hn0sXLZ5yJcxtmuY-ItQfYD7hBtHwt7A) +~~优先使用训练提供的权重文件,如果训练的权重文件网上能获则需给出网址,否则需要给出从哪获取权重文件。如果训练没有提供权重则使用开源代码仓的权重文件。需要给出权重文件名~~ + +4.数据集 +[获取Market1501](http://www.liangzheng.org/Project/project_reid.html),并重命名为market1501 + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + **评测结果:** +| 模型 | 官网pth精度 | 310离线推理精度 | gpu性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| ReID-strong-baseline bs1 | [rank1:94.5% mAP:85.9%](https://github.com/michuanhaohao/reid-strong-baseline) | rank1:94.5% mAP:85.9% | 992.9994fps | 1446.188fps | +| ReID-strong-baseline bs16 | [rank1:94.5% mAP:85.9%](https://github.com/michuanhaohao/reid-strong-baseline) | rank1:94.5% mAP:85.9% | 2211.7074fps | 2588.56fps | + +备注: +加上TEST.NECK_FEAT "('before')" TEST.FEAT_NORM "('no')"导出的onnx可以进行离线推理 +不加TEST.NECK_FEAT "('before')" TEST.FEAT_NORM "('no')"导出的onnx转换的om精度与官网精度一致 + + diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_postprocess.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_postprocess.py" new file mode 100644 index 0000000000000000000000000000000000000000..0af4cb769d1e1e998e62e37aee621d542d94115a --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_postprocess.py" @@ -0,0 +1,73 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +sys.path.append('./reid-strong-baseline') +import os +import argparse +import glob +import re +import numpy as np +import torch +from utils.reid_metric import R1_mAP + +def get_pred_label(label_dir, pre_dir): + img_paths = glob.glob(os.path.join(label_dir, '*.jpg')) + pattern = re.compile(r'([-\d]+)_c(\d)') + + outputs = [] + for img_path in img_paths: + pid, camid = map(int, pattern.search(img_path).groups()) + if pid == -1: continue # junk images are just ignored + camid -= 1 # index starts from 0 + + filename = img_path.split("/")[-1] + if filename[-8:] == ".jpg.jpg": + bin_file = filename[:-8] + "_1.bin" + else: + bin_file = filename[:-4] + "_1.bin" + output = np.fromfile(os.path.join(pre_dir, bin_file), dtype="float32") + output = torch.from_numpy(output) + output = output.unsqueeze(0) + + pid = torch.from_numpy(np.array([pid,])) + camid = torch.from_numpy(np.array([camid,])) + outputs.append((output, pid, camid)) + + return outputs + +def eval(query_dir, gallery_dir, pred_dir): + + query = get_pred_label(query_dir, pred_dir) + gallery = get_pred_label(gallery_dir, pred_dir) + outputs = query + gallery + + num_query = 3368 + eval = R1_mAP(num_query, max_rank=50, feat_norm="yes") + eval.reset() + for output in outputs: + eval.update(output) + cmc, mAP = eval.compute() + print('Validation Results') + print("mAP: {:.1%}".format(mAP)) + for r in [1, 5, 10]: + print("CMC curve, Rank-{:<3}:{:.1%}".format(r, cmc[r - 1])) + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--query_dir", default="./data/market1501/query") + parser.add_argument("--gallery_dir", default="./data/market1501/bounding_box_test") + parser.add_argument("--pred_dir", default="./result/dumpOutput_device0/") + args = parser.parse_args() + eval(args.query_dir, args.gallery_dir, args.pred_dir) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_preprocess.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_preprocess.py" new file mode 100644 index 0000000000000000000000000000000000000000..c296fb121ebb4f91f918d885d51b9288c451d70e --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_preprocess.py" @@ -0,0 +1,56 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import numpy as np +from PIL import Image +from torchvision import transforms +import multiprocessing + +preprocess = transforms.Compose([ + transforms.Resize([256, 128]), + transforms.ToTensor(), + transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) +]) + +def gen_input_bin(file_batches, batch): + i = 0 + for file in file_batches[batch]: + if ".db" in file: + continue + i = i + 1 + print("batch", batch, file, "===", i) + + input_image = Image.open(os.path.join(src_path, file)).convert('RGB') + input_tensor = preprocess(input_image) + img = np.array(input_tensor).astype(np.float32) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + +def ReID_preprocess(src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + +if __name__ == '__main__': + src_path = sys.argv[1] + save_path = sys.argv[2] + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + ReID_preprocess(src_path, save_path) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_pth2onnx.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_pth2onnx.py" new file mode 100644 index 0000000000000000000000000000000000000000..659451d4ade18d31b45aecf33889d3b548e4c5ba --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/ReID_pth2onnx.py" @@ -0,0 +1,63 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import argparse +import torch +import torch.onnx +sys.path.append('./reid-strong-baseline') +from config import cfg +from modeling import build_model + +from collections import OrderedDict +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "classifier" in k: + continue + new_state_dict[k] = v + return new_state_dict + +def main(): + parser = argparse.ArgumentParser(description="ReID Baseline Inference") + parser.add_argument( + "--config_file", default="", help="path to config file", type=str + ) + parser.add_argument("opts", help="Modify config options using the command-line", default=None, + nargs=argparse.REMAINDER) + args = parser.parse_args() + + cfg.merge_from_file(args.config_file) + cfg.merge_from_list(args.opts) + cfg.freeze() + + num_classes = 751 + model = build_model(cfg, num_classes) + checkpoint = torch.load(cfg.TEST.WEIGHT, map_location='cpu') + #checkpoint = proc_nodes_module(checkpoint) + model.load_state_dict(checkpoint) + model.eval() + + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 256, 128) + export_onnx_file = "ReID.onnx" + + torch.onnx.export(model, dummy_input, export_onnx_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=True) + +if __name__ == '__main__': + main() diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/env.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/env.sh" new file mode 100644 index 0000000000000000000000000000000000000000..49be8f16a045f6e4e61666ecc8a5da811c15fd80 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/env.sh" @@ -0,0 +1,8 @@ +#! /bin/bash + +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/gen_dataset_info.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/gen_dataset_info.py" new file mode 100644 index 0000000000000000000000000000000000000000..f80f45a34c450d57f0ea49d93167892d93a30e88 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/gen_dataset_info.py" @@ -0,0 +1,60 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/modelzoo_level.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/modelzoo_level.txt" new file mode 100644 index 0000000000000000000000000000000000000000..9e95396651cc4382fe60ee1ee053674f527a448c --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/modelzoo_level.txt" @@ -0,0 +1,4 @@ +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK +PerfStatus:POK \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/requirements.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/requirements.txt" new file mode 100644 index 0000000000000000000000000000000000000000..4cda32191fe9ee542596389f75f4377bd38521d8 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/requirements.txt" @@ -0,0 +1,8 @@ +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +numpy == 1.20.3 +Pillow == 8.2.0 +opencv-python == 4.5.2.54 +yacs == 0.1.8 +pytorch-ignite == 0.4.5 \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/eval_acc_perf.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/eval_acc_perf.sh" new file mode 100644 index 0000000000000000000000000000000000000000..1bfa7cf5aa72efe9118b025030f52d9c17b89248 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/eval_acc_perf.sh" @@ -0,0 +1,72 @@ +#!/bin/bash + +datasets_path="/root/datasets/" + +for para in $* +do + if [[ $para == --datasets_path* ]]; then + datasets_path=`echo ${para#*=}` + fi +done + +arch=`uname -m` +rm -rf ./prep_dataset_query +rm -rf ./prep_dataset_gallery +python3.7 ReID_preprocess.py ${datasets_path}/market1501/query ./prep_dataset_query +python3.7 ReID_preprocess.py ${datasets_path}/market1501/bounding_box_test ./prep_dataset_gallery +mv prep_dataset_gallery/* prep_dataset_query/ +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 gen_dataset_info.py bin ./prep_dataset_query ./prep_bin.info 128 256 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +source env.sh +rm -rf result/dumpOutput_device0 +./benchmark.${arch} -model_type=vision -device_id=0 -batch_size=1 -om_path=./ReID_bs1.om -input_text_path=./prep_bin.info -input_width=128 -input_height=256 -output_binary=True -useDvpp=False +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +rm -rf result/dumpOutput_device1 +./benchmark.${arch} -model_type=vision -device_id=1 -batch_size=16 -om_path=./ReID_bs16.om -input_text_path=./prep_bin.info -input_width=128 -input_height=256 -output_binary=True -useDvpp=False +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 ReID_postprocess.py --query_dir=${datasets_path}/market1501/query --gallery_dir=${datasets_path}/market1501/bounding_box_test --pred_dir=./result/dumpOutput_device0 > result_bs1.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 ReID_postprocess.py --query_dir=${datasets_path}/market1501/query --gallery_dir=${datasets_path}/market1501/bounding_box_test --pred_dir=./result/dumpOutput_device1 > result_bs16.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +echo "====accuracy data====" +python3.7 test/parse.py result_bs1.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 test/parse.py result_bs16.json +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +echo "====performance data====" +python3.7 test/parse.py result/perf_vision_batchsize_1_device_0.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 test/parse.py result/perf_vision_batchsize_16_device_1.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +echo "success" \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/parse.py" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/parse.py" new file mode 100644 index 0000000000000000000000000000000000000000..6d5a1293288dce8bfc70f79ecf6551acafed6b81 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/parse.py" @@ -0,0 +1,33 @@ +# Copyright 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + print(content) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + 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 diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/perf_g.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/perf_g.sh" new file mode 100644 index 0000000000000000000000000000000000000000..a1c5a64463d3165909d67bffe256b4f69732e50e --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/perf_g.sh" @@ -0,0 +1,19 @@ +trtexec --onnx=ReID.onnx --fp16 --shapes=image:1x3x256x128 > ReID_bs1.log +perf_str=`grep "GPU.* mean.*ms$" ReID_bs1.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" ReID_bs1.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' + +trtexec --onnx=ReID.onnx --fp16 --shapes=image:16x3x256x128 > ReID_bs16.log +perf_str=`grep "GPU.* mean.*ms$" ReID_bs16.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" ReID_bs16.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs16 fps:%.3f\n", 1000*1/('$perf_num'/16)}' \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/pth2om.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/pth2om.sh" new file mode 100644 index 0000000000000000000000000000000000000000..393275a3c0ecde085fcc643e29e828d28d81dd67 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/cv/ReID/ReID-strong-baseline/test/pth2om.sh" @@ -0,0 +1,19 @@ +#!/bin/bash + +rm -rf ReID.onnx +python3.7 ReID_pth2onnx.py --config_file='reid-strong-baseline/configs/softmax_triplet_with_center.yml' MODEL.PRETRAIN_CHOICE "('self')" TEST.WEIGHT "('market_resnet50_model_120_rank1_945.pth')" TEST.NECK_FEAT "('before')" TEST.FEAT_NORM "('no')" +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi + +rm -rf ReID_bs1.om ReID_bs16.om +source env.sh +atc --framework=5 --model=ReID.onnx --output=ReID_bs1 --input_format=NCHW --input_shape="image:1,3,256,128" --log=debug --soc_version=Ascend310 +atc --framework=5 --model=ReID.onnx --output=ReID_bs16 --input_format=NCHW --input_shape="image:16,3,256,128" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" + +if [ -f "ReID_bs1.om" ] && [ -f "ReID_bs16.om" ]; then + echo "success" +else + echo "fail!" +fi \ No newline at end of file diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/.keep" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/research/.keep" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/.keep" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/research/.keep" diff --git "a/AscendPytorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272FAQ.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-FAQ.md" similarity index 100% rename from "AscendPytorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272FAQ.md" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-FAQ.md" diff --git "a/docs/XxxxNet\347\275\221\347\273\234\346\250\241\345\236\213[\344\272\244\344\273\230\345\206\205\345\256\271]\346\265\213\350\257\225\346\212\245\345\221\212.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-XxxxNet\347\275\221\347\273\234\346\250\241\345\236\213[\344\272\244\344\273\230\345\206\205\345\256\271]\346\265\213\350\257\225\346\212\245\345\221\212.docx" similarity index 100% rename from "docs/XxxxNet\347\275\221\347\273\234\346\250\241\345\236\213[\344\272\244\344\273\230\345\206\205\345\256\271]\346\265\213\350\257\225\346\212\245\345\221\212.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-XxxxNet\347\275\221\347\273\234\346\250\241\345\236\213[\344\272\244\344\273\230\345\206\205\345\256\271]\346\265\213\350\257\225\346\212\245\345\221\212.docx" diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/.keep" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274\344\271\246.docx" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/.keep" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274\344\271\246.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\265\213\350\257\225\346\212\245\345\221\212.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\265\213\350\257\225\346\212\245\345\221\212.docx" new file mode 100644 index 0000000000000000000000000000000000000000..fd5fb68b511e1abc0ed06f9b2da249026fa813cb Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\265\213\350\257\225\346\212\245\345\221\212.docx" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-issue\346\250\241\346\235\277.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-issue\346\250\241\346\235\277.md" new file mode 100644 index 0000000000000000000000000000000000000000..d47164e36c4d1d3c7ab1cf5234ea6fb06bacc3f0 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-issue\346\250\241\346\235\277.md" @@ -0,0 +1,21 @@ +标题: +[众智-PyTorch离线推理] [问题求助] - xx算子耗时长 + + +一、问题现象(附截图): +xx模型迁移到Ascend310上,pytorch->onnx->om,模型性能不达标,原因为算子性能差,profiling数据截图如下: + + + + +二、软件版本: +-- Pytorch 版本 (源码或二进制): +-- Python 版本 (e.g., Python 3.7.5): +-- 操作系统版本 (e.g., Ubuntu 18.04): +-- CANN 版本 (e.g., CANNN 5.0.1): + + +提供附件: +1. profiling原始数据 +2. onnx模型与bs16的om模型 +3.PyToch离线推理xxx模型性能不达标测试报告.docx \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-models_result.xlsx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-models_result.xlsx" new file mode 100644 index 0000000000000000000000000000000000000000..1f95acd26098ea6f384121566b7ab6b8b8ef27b3 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-models_result.xlsx" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\347\216\257\345\242\203\351\203\250\347\275\262\344\270\216\344\275\277\347\224\250\350\257\264\346\230\216.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\347\216\257\345\242\203\351\203\250\347\275\262\344\270\216\344\275\277\347\224\250\350\257\264\346\230\216.md" new file mode 100644 index 0000000000000000000000000000000000000000..5b38f1e95710f16a487ebb1da2bd36bcae99ec68 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\347\216\257\345\242\203\351\203\250\347\275\262\344\270\216\344\275\277\347\224\250\350\257\264\346\230\216.md" @@ -0,0 +1,115 @@ +# 310服务器部署与说明 +- CANN包安装 + - 1.获取CANN包 + https://www.hiascend.com/software/cann/community + - 2.卸载老CANN包 + bash A300-3000-3010-npu-firmware_1.77.22.6.220.run --uninstall + rm -rf /usr/local/Ascend + reboot + - 3.安装CANN包 + bash A300-3010-npu-driver_21.0.1_ubuntu18.04-x86_64.run --full + bash A300-3000-3010-npu-firmware_1.77.22.6.220.run --full + reboot + bash Ascend-cann-toolkit_5.0.1_linux-x86_64.run --install + - 4.获取benchmark工具 + unzip Ascend-cann-benchmark_5.0.1-Linux-x86_64.zip + + >**说明:** + > + >若报无HwHiAiUser用户则执行useradd HwHiAiUser + >安装固件若报Not a physical-machine, firmware upgrade does not support.则不必安装固件 + >若报错ls: cannot access '.../5.0.1/x86_64-linux/toolkit/python/site-packages/bin': No such file or directory,则```export PATH=/usr/local/python3.7.5/bin:$PATH;export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH``` + >可以指定安装路径bash Ascend-cann-toolkit_5.0.1_linux-x86_64.run --install-path=/home/test --install,然后环境变量的CANN包路径也相应设置 为/home/test/Ascend/ascend-toolkit/latest + +- 添加普通用户 + useradd -m your_name + passwd your_name + usermod -s /bin/bash your_name + + 修改/etc/sudoers添加your_name ALL=(ALL:ALL) ALL + your_name用户便可使用sudo命令 + + 普通用户通过sudo执行atc报错找不到动态库,需要修改: + 修改/etc/sudoers将Defaults env_reset改成Defaults !env_reset + 修改/etc/bash.bashrc添加```alias sudo='sudo env PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH'``` + +- 请使用conda安装python的库,将python的库安装在自己的conda环境里,修改这些库的代码不会影响其他用户 + 查看已有环境: + conda env list + 创建自己的conda环境: + conda create -n your_env_name python=3.7.5 + 进入环境: + conda activate your_env_name + 查看环境安装的python的库: + conda list + 只在该环境中安装py软件包: + https://anaconda.org/ 网址搜索包的安装命令 + conda install -c pytorch pytorch + conda install -c pytorch torchvision + conda install -c conda-forge onnx=1.9.0 + 查看安装路径: + python3.7 + import torchvision + print(torchvision.__file__) + 退出环境: + conda deactivate + 删除环境: + conda remove -n your_env_name --all + +- 使用说明: + - 请联系华为方申请登录服务器的普通用户名与密码 + - /home/下每个用户创建一个自己的目录,原则上只允许用户在自己的这个目录下开发,不要修改其它目录的东西 + - 不要随意更新CANN包与驱动包,修改系统文件,系统密码等 + - /opt/npu是共享的数据集盘目录,该目录仅用来存放共享的数据集,不可向该目录盘写其它数据 + - 每个模型使用到的通用数据集都放在/root/datasets/目录,除/root/datasets与/opt/npu外,不应在其它目录存放通用的数据集 + - 环境中默认安装的商用版CANN包放在/root/commerce_packages/目录下 + - 如果需要安装最新社区版CANN包可以安装在/root/cann_community/目录下 + +# t4服务器部署与说明 +- 安装cuda,cudnn,tensorrt + - 安装cuda + https://developer.nvidia.cn/cuda-toolkit-archive: + wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda_11.0.2_450.51.05_linux.run + sh cuda_11.0.2_450.51.05_linux.run + 安装过程不要选driver + 修改/etc/bash.bashrc添加: + ``` + export CUDA_HOME=/usr/local/cuda + export PATH=$PATH:$CUDA_HOME/bin + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_HOME/lib64 + ``` + - 安装cudnn + https://developer.nvidia.cn/rdp/cudnn-download: + wget https://developer.nvidia.cn/compute/machine-learning/cudnn/secure/8.2.0.53/11.3_04222021/cudnn-11.3-linux-x64-v8.2.0.53.tgz + cp cuda/include/cudnn.h /usr/local/cuda/include/ + cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ + - 安装tensorRT + https://developer.nvidia.cn/nvidia-tensorrt-download: + wget https://developer.nvidia.cn/compute/machine-learning/tensorrt/secure/7.2.3/tars/TensorRT-7.2.3.4.Ubuntu-18.04.x86_64-gnu.cuda-11.0.cudnn8.1.tar.gz + tar zxvf TensorRT-7.2.3.4.Ubuntu-18.04.x86_64-gnu.cuda-11.0.cudnn8.1.tar.gz -C /usr/local/ + 修改/etc/bash.bashrc添加: + ``` + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/TensorRT-7.2.3.4/lib + export PATH=$PATH:/usr/local/TensorRT-7.2.3.4/targets/x86_64-linux-gnu/bin + ``` + +- 添加普通用户 + useradd -m your_name + passwd your_name + usermod -s /bin/bash your_name + + t4上在线推理需要使用sudo安装库: + 修改/etc/sudoers添加your_name ALL=(ALL:ALL) ALL + your_name用户便可使用sudo命令 + 配置t4代理以访问外网: + export http_proxy=http://192.168.88.254:8080 + export https_proxy=http://192.168.88.254:8080 + +- 使用说明: + - /home/下每个普通用户创建一个自己的目录,原则上只允许用户在自己的这个目录下开发,不要修改其它目录的东西 + - 测试时请确保t4卡没有运行其它测试任务,使用nvidia-smi查看卡是否处于空闲态 + - t4上使用trtexec一条命令即可测试onnx模型性能,一般模型性能测试在半小时到半天之间可完成,测试完成后请及时退出登录 + - 不要更新CUDA驱动包与tensorRT,修改系统文件,系统密码等 + - 如果onnx不支持离线推理,需要在t4上在线推理测试性能,建议共用一台t4给普通用户sudo权限测试在线推理,而其它t4用来测试onnx离线推理性能不需要给普通用户sudo权限 + + diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\350\277\233\345\261\225.xlsx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\350\277\233\345\261\225.xlsx" new file mode 100644 index 0000000000000000000000000000000000000000..fdda2d26fc8f6411dc83e8d23ad7a7c55ae4fbe7 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\350\277\233\345\261\225.xlsx" differ diff --git "a/AscendPyTorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272\351\252\214\346\224\266\346\214\207\345\215\227.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\351\252\214\346\224\266\346\214\207\345\215\227.md" similarity index 95% rename from "AscendPyTorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272\351\252\214\346\224\266\346\214\207\345\215\227.md" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\351\252\214\346\224\266\346\214\207\345\215\227.md" index e0449aaa17214ddce93b90e67c663e7f3fabfe80..70c0cfcd29822866bf24f70ba4ef12660033079f 100644 --- "a/AscendPyTorch\346\250\241\345\236\213\346\216\250\347\220\206\344\274\227\346\231\272\351\252\214\346\224\266\346\214\207\345\215\227.md" +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-\351\252\214\346\224\266\346\214\207\345\215\227.md" @@ -90,6 +90,7 @@ ``` - 在pr提交的内容栏里编辑issue的链接即可关联对应的issue,问题解决后issue将自动关闭 - 示例链接 https://gitee.com/ascend/modelzoo/issues/I3FI5L?from=project-issue +- [性能不达标issue模板](https://gitee.com/pengyeqing/ascend-pytorch-crowdintelligence-doc/blob/master/%E4%BC%97%E6%99%BA%E6%8E%A8%E7%90%86issue) ### 附: pr检视 @@ -125,6 +126,14 @@ 该文件是验收测试说明,主要是准备环境,pip3.7 install -r requirements.txt可能会重新安装某版本pytorch,验收时根据需要决定是否执行 参见模板[test/README.md](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50/test/README.md) +- 如果使用补丁文件修改了模型代码则将补丁打入模型代码,如果需要引用模型代码仓的类或函数通过sys.path.append(r"./pytorch-nested-unet")添加搜索路径 + 预处理脚本不需要improt该脚本没有使用的库 +参见https://gitee.com/ascend/modelzoo/pulls/2309 +参见https://gitee.com/ascend/modelzoo/pulls/2585 +- 模型不支持动态onnx,性能不达标等特殊情况需要在pr备注与性能优化里说明 +参见https://gitee.com/ascend/modelzoo/pulls/2122 +参见https://gitee.com/ascend/modelzoo/pulls/2328 + ### 附: 模型推理指导中的交付标准与规范 - 交付标准 - 精度: diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/.keep" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\346\241\210\344\276\213/\345\212\237\350\203\275\346\211\223\351\200\232/.keep" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/.keep" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\346\241\210\344\276\213/\345\212\237\350\203\275\346\211\223\351\200\232/.keep" diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/.keep" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\346\241\210\344\276\213/\346\200\247\350\203\275\344\274\230\345\214\226/.keep" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/classification/.keep" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\346\241\210\344\276\213/\346\200\247\350\203\275\344\274\230\345\214\226/.keep" diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/.keep" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\350\257\225/.keep" similarity index 100% rename from "onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/cv/segmentation/.keep" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\350\257\225/.keep" diff --git a/docs/models_result.xlsx b/docs/models_result.xlsx deleted file mode 100644 index 6569e5c353d1669a4fe7bf95610263775ccf0e6b..0000000000000000000000000000000000000000 Binary files a/docs/models_result.xlsx and /dev/null differ diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/nlp/.keep" "b/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/benchmark/nlp/.keep" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/official/.keep" "b/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/official/.keep" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/research/.keep" "b/onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274/research/.keep" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000