已合并
[西安交通大学][高校贡献][Pytorch迁移1.8][EfficientNet-B3]初次提交 #1766
AtomGit-Bot创建于 2022年9月9日
[西安交通大学][高校贡献][Pytorch迁移1.8][EfficientNet-B3]初次提交 #1766
已合并
AtomGit-Bot创建于 2022年9月9日
refs/pull/1766/head合入到master
8 个文件变更+233-57
APyTorch/contrib/cv/classification/EfficientNet-B3/README -raw.md+52-0
@@ -0,0 +1,52 @@
1# EfficientNet-B3
2 
3This implements training of Efficientnet-B3 on the ImageNet dataset, mainly modified from [pycls](https://github.com/facebookresearch/pycls).
4 
5## EfficientNet-B3 Detail
6 
7For details, see[pycls](https://github.com/facebookresearch/pycls).
8 
9 
10## Requirements
11 
12- Install PyTorch ([pytorch.org](http://pytorch.org))
13- pip install pycls
14- git clone https://github.com/facebookresearch/pycls
15- pip install -r requirements.txt
16- modify path of dataset in pycls/datasets/loader.py, you can modify the variable _DATA_DIR to your path of imagenet dataset.
17 
18## Training
19 
20To train a model, run scripts with the desired model architecture and the path to the ImageNet dataset:
21 
22```bash
23# 1p train 1p
24bash test/train_full_1p.sh --data_path={data/path} # train accuracy
25 
26bash test/train_performance_1p.sh --data_path={data/path} # train performance
27 
28# 8p train 8p
29bash test/train_full_8p.sh --data_path={data/path} # train accuracy
30 
31bash test/train_performance_8p.sh --data_path={data/path} # train performance
32 
33# 1p eval 1p
34bash test/train_eval_8p.sh --data_path={data/path}
35 
36# online inference demo
37python3.7 demo.py
38 
39# To ONNX
40python3.7.5 pthtar2onnx.py
41 
42```
43 
44## EfficientNet-B3 training result
45 
46| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type |
47| :----: | :--: | :------: | :----: | :------: |
48| - | 267 | 1 | 100 | O2 |
49| 77.3418 | 1558 | 8 | 100 | O2 |
50 
51 
52 
MPyTorch/contrib/cv/classification/EfficientNet-B3/README.md+174-52
@@ -1,52 +1,174 @@
1# EfficientNet-B31# EfficientNet-B3 for PyTorch
2 2 
3This implements training of Efficientnet-B3 on the ImageNet dataset, mainly modified from [pycls](https://github.com/facebookresearch/pycls).3- [概述](概述.md)
4 4- [准备训练环境](准备训练环境.md)
5## EfficientNet-B3 Detail 5- [开始训练](开始训练.md)
6 6- [训练结果展示](训练结果展示.md)
7For details, see[pycls](https://github.com/facebookresearch/pycls).7- [版本说明](版本说明.md)
8 8 
9 9 
10## Requirements 10 
11 11# 概述
12- Install PyTorch ([pytorch.org](http://pytorch.org))12 
13- pip install pycls13## 简述
14- git clone https://github.com/facebookresearch/pycls14 
15- pip install -r requirements.txt15EfficientNet是Google研究小组2019年在论文《EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks》中推出的新模型(Tan and Le 2019),该模型基于网络深度、宽度和输入分辨率三个维度的缩放来寻找最优模型。
16- modify path of dataset in pycls/datasets/loader.py, you can modify the variable _DATA_DIR to your path of imagenet dataset.16 
17 17- 参考实现:
18## Training 18 
19 19 ```
20To train a model, run scripts with the desired model architecture and the path to the ImageNet dataset:20 url=https://github.com/facebookresearch/pycls
21 21 commit_id=ee89cecb0e295b8037843e7e28344b156a847554
22```bash22 ```
23# 1p train 1p23 
24bash test/train_full_1p.sh --data_path={data/path} # train accuracy24- 适配昇腾 AI 处理器的实现:
25 25 
26bash test/train_performance_1p.sh --data_path={data/path} # train performance26 ```
27 27 url=https://gitee.com/ascend/ModelZoo-PyTorch.git
28# 8p train 8p28 code_path=PyTorch/contrib/cv/classification
29bash test/train_full_8p.sh --data_path={data/path} # train accuracy29 ```
30 30
31bash test/train_performance_8p.sh --data_path={data/path} # train performance31- 通过Git获取代码方法如下:
32 32 
33# 1p eval 1p33 ```
34bash test/train_eval_8p.sh --data_path={data/path}34 git clone {url} # 克隆仓库的代码
35 35 cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
36# online inference demo 36 ```
37python3.7 demo.py37
38 38- 通过单击“立即下载”,下载源码包。
39# To ONNX39 
40python3.7.5 pthtar2onnx.py40# 准备训练环境
41 41 
42```42## 准备环境
43 43 
44## EfficientNet-B3 training result 44- 当前模型支持的固件与驱动、 CANN 以及 PyTorch 如下表所示。
45 45 
46| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type |46 **表 1** 版本配套表
47| :----: | :--: | :------: | :----: | :------: |47 
48| - | 267 | 1 | 100 | O2 |48 | 配套 | 版本 |
49| 77.3418 | 1558 | 8 | 100 | O2 |49 | ---------- | ------------------------------------------------------------ |
50 50 | 固件与驱动 | [5.1.RC2](https://www.hiascend.com/hardware/firmware-drivers?tag=commercial) |
51 51 | CANN | [5.1.RC2](https://www.hiascend.com/software/cann/commercial?version=5.1.RC2) |
52 52 | PyTorch | [1.8.1](https://gitee.com/ascend/pytorch/tree/master/) |
53 
54- 环境准备指导。
55 
56 请参考《[Pytorch框架训练环境准备](https://www.hiascend.com/document/detail/zh/ModelZoo/pytorchframework/ptes)》。
57
58- 安装依赖。
59 ```
60 pip install pycls
61 pip install -r requirements.txt
62 ```
63 
64 
65## 准备数据集
66 
671. 获取数据集。
68 
69 用户自行获取原始数据集imagenet,将数据集上传到服务器并解压。
70 
71 注:为方便运行,数据集应该存放在如下文件路径中:
72 ```
73 ./Efficientnet-B3/pycls/datasets/data
74 # 数据集软链接方式
75 ln -s {data/path} EfficientNet-B3/pycls/datasets/data
76 ```
77 数据集目录结构参考如下所示:
78 ```
79 ├── ImageNet
80 ├──train
81 ├──类别1
82 │──图片1
83 │──图片2
84 │ ...
85 ├──类别2
86 │──图片1
87 │──图片2
88 │ ...
89 ├──...
90 ├──val
91 ├──类别1
92 │──图片1
93 │──图片2
94 │ ...
95 ├──类别2
96 │──图片1
97 │──图片2
98 │ ...
99 ```
100 
101 > **说明:**
102 >该数据集的训练过程脚本只作为一种参考示例。
103 
1042. 数据预处理。
105- 在pycls/datasets/loader.py中修改数据集的路径,你可以将变量_DATA_DIR修改为你的imagenet数据集的路径。
106 
107 
108# 开始训练
109 
110## 训练模型
111 
1121. 进入解压后的源码包根目录。
113 
114 ```
115 cd /${模型文件夹名称}
116 ```
117 
1182. 运行训练脚本。
119 该模型支持单机单卡训练和单机8卡训练。
120 
121 - 单机单卡训练
122 
123 启动单卡训练。
124 
125 ```
126 bash ./test/train_performance_1p.sh --data_path={data/path} # 1p性能
127 bash ./test/train_full_1p.sh --data_path={data/path} # 1p精度
128 ```
129 
130 - 单机8卡训练
131 
132 启动8卡训练。
133 ```
134 bash ./test/train_performance_8p.sh --data_path={data/path} # 8p性能
135 bash ./test/train_full_8p.sh --data_path={data/path} # 8p精度 完成100个epoch训练大约27h
136 bash ./test/train_eval_8p.sh --data_path={data/path} # 8p验证
137 ```
138 
139 --data\_path参数填写数据集路径。
140 
141 模型训练脚本参数说明如下。
142 
143 ```
144 公共参数:
145 --device //使用设备,gpu或npu
146 --cfg //使用yaml配置文件路径
147 --rank_id //默认卡号
148 --device_id //默认设备号
149 ```
150
151 
152# 训练结果展示
153 
154**表 2** 训练结果展示表
155 
156| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | Torch |
157| :----: | :--: | :------: | :----: | :------: | :---: |
158| - | 267 | 1 | 1 | O2 | 1.5 |
159| 77.3418 | 1558 | 8 | 100 | O2 | 1.5 |
160| - | 356 | 1 | 1 | O2 | 1.8 |
161| 77.0613 | 2236 | 8 | 100 | O2 | 1.8 |
162 
163 
164# 版本说明
1652022.08.01:更新pytorch1.8版本,重新发布。
166 
167## 已知问题
168无。
169 
170 
171 
172 
173 
174 
MPyTorch/contrib/cv/classification/EfficientNet-B3/test/train_eval_8p.sh+1-1
@@ -41,7 +41,7 @@ fi
41 41 
42# 数据集软链到脚本内部42# 数据集软链到脚本内部
43cur_path=`pwd`43cur_path=`pwd`
44default_data_path=${cur_path}/pycls/datasets/data/44default_data_path=${cur_path}/pycls/datasets/data
45rm -rf ${default_data_path}/imagenet45rm -rf ${default_data_path}/imagenet
46ln -s ${data_path} ${default_data_path}/imagenet46ln -s ${data_path} ${default_data_path}/imagenet
47 47 
MPyTorch/contrib/cv/classification/EfficientNet-B3/test/train_full_1p.sh+1-1
@@ -49,7 +49,7 @@ fi
49 49 
50# 数据集软链到脚本内50# 数据集软链到脚本内
51cur_path=`pwd`51cur_path=`pwd`
52default_data_path=${cur_path}/pycls/datasets/data/52default_data_path=${cur_path}/pycls/datasets/data
53rm -rf ${default_data_path}/imagenet53rm -rf ${default_data_path}/imagenet
54ln -s ${data_path} ${default_data_path}/imagenet54ln -s ${data_path} ${default_data_path}/imagenet
55 55 
MPyTorch/contrib/cv/classification/EfficientNet-B3/test/train_full_8p.sh+1-1
@@ -33,7 +33,7 @@ fi
33 33 
34# 数据集软链到脚本内部34# 数据集软链到脚本内部
35cur_path=`pwd`35cur_path=`pwd`
36default_data_path=${cur_path}/pycls/datasets/data/36default_data_path=${cur_path}/pycls/datasets/data
37rm -rf ${default_data_path}/imagenet37rm -rf ${default_data_path}/imagenet
38ln -s ${data_path} ${default_data_path}/imagenet38ln -s ${data_path} ${default_data_path}/imagenet
39 39 
MPyTorch/contrib/cv/classification/EfficientNet-B3/test/train_performance_1p.sh+1-1
@@ -49,7 +49,7 @@ fi
49 49 
50# 数据集软链到脚本内50# 数据集软链到脚本内
51cur_path=`pwd`51cur_path=`pwd`
52default_data_path=${cur_path}/pycls/datasets/data/52default_data_path=${cur_path}/pycls/datasets/data
53rm -rf ${default_data_path}/imagenet53rm -rf ${default_data_path}/imagenet
54ln -s ${data_path} ${default_data_path}/imagenet54ln -s ${data_path} ${default_data_path}/imagenet
55 55 
MPyTorch/contrib/cv/classification/EfficientNet-B3/test/train_performance_8p.sh+1-1
@@ -33,7 +33,7 @@ fi
33 33 
34# 数据集软链到脚本内部34# 数据集软链到脚本内部
35cur_path=`pwd`35cur_path=`pwd`
36default_data_path=${cur_path}/pycls/datasets/data/36default_data_path=${cur_path}/pycls/datasets/data
37rm -rf ${default_data_path}/imagenet37rm -rf ${default_data_path}/imagenet
38ln -s ${data_path} ${default_data_path}/imagenet38ln -s ${data_path} ${default_data_path}/imagenet
39 39 
MPyTorch/contrib/cv/classification/EfficientNet-B3/tools/train_net.py+2-0
@@ -29,6 +29,8 @@ import pycls.core.trainer as trainer
29from pycls.core.config import cfg29from pycls.core.config import cfg
30import argparse,sys,os,torch30import argparse,sys,os,torch
31import torch31import torch
32if torch.__version__>= '1.8':
33 import torch_npu
32 34 
33def init_process_group(proc_rank, world_size, device_type="npu", port="29588"):35def init_process_group(proc_rank, world_size, device_type="npu", port="29588"):
34 """Initializes the default process group."""36 """Initializes the default process group."""