已合并
[西安交通大学][高校贡献][Pytorch迁移1.8][EfficientNet-B3]初次提交 #1766
AtomGit-Bot创建于 2022年9月9日
[西安交通大学][高校贡献][Pytorch迁移1.8][EfficientNet-B3]初次提交 #1766
已合并
从refs/pull/1766/head合入到master
共 8 个文件变更+233-57
| @@ -0,0 +1,52 @@ | |||
| 1 | # EfficientNet-B3 | ||
| 2 | |||
| 3 | This implements training of Efficientnet-B3 on the ImageNet dataset, mainly modified from [pycls](https://github.com/facebookresearch/pycls). | ||
| 4 | |||
| 5 | ## EfficientNet-B3 Detail | ||
| 6 | |||
| 7 | For 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 | |||
| 20 | To train a model, run scripts with the desired model architecture and the path to the ImageNet dataset: | ||
| 21 | |||
| 22 | ```bash | ||
| 23 | # 1p train 1p | ||
| 24 | bash test/train_full_1p.sh --data_path={data/path} # train accuracy | ||
| 25 | |||
| 26 | bash test/train_performance_1p.sh --data_path={data/path} # train performance | ||
| 27 | |||
| 28 | # 8p train 8p | ||
| 29 | bash test/train_full_8p.sh --data_path={data/path} # train accuracy | ||
| 30 | |||
| 31 | bash test/train_performance_8p.sh --data_path={data/path} # train performance | ||
| 32 | |||
| 33 | # 1p eval 1p | ||
| 34 | bash test/train_eval_8p.sh --data_path={data/path} | ||
| 35 | |||
| 36 | # online inference demo | ||
| 37 | python3.7 demo.py | ||
| 38 | |||
| 39 | # To ONNX | ||
| 40 | python3.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 | |||
| @@ -1,52 +1,174 @@ | |||
| 1 | # EfficientNet-B3 | 1 | # EfficientNet-B3 for PyTorch |
| 2 | 2 | ||
| 3 | This 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) | |
| 7 | For 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 pycls | 13 | ## 简述 |
| 14 | - git clone https://github.com/facebookresearch/pycls | 14 | |
| 15 | - pip install -r requirements.txt | 15 | EfficientNet是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 | ``` | |
| 20 | To 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 | ```bash | 22 | ``` |
| 23 | # 1p train 1p | 23 | |
| 24 | bash test/train_full_1p.sh --data_path={data/path} # train accuracy | 24 | - 适配昇腾 AI 处理器的实现: |
| 25 | 25 | ||
| 26 | bash test/train_performance_1p.sh --data_path={data/path} # train performance | 26 | ``` |
| 27 | 27 | url=https://gitee.com/ascend/ModelZoo-PyTorch.git | |
| 28 | # 8p train 8p | 28 | code_path=PyTorch/contrib/cv/classification |
| 29 | bash test/train_full_8p.sh --data_path={data/path} # train accuracy | 29 | ``` |
| 30 | 30 | ||
| 31 | bash test/train_performance_8p.sh --data_path={data/path} # train performance | 31 | - 通过Git获取代码方法如下: |
| 32 | 32 | ||
| 33 | # 1p eval 1p | 33 | ``` |
| 34 | bash test/train_eval_8p.sh --data_path={data/path} | 34 | git clone {url} # 克隆仓库的代码 |
| 35 | 35 | cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换 | |
| 36 | # online inference demo | 36 | ``` |
| 37 | python3.7 demo.py | 37 | |
| 38 | 38 | - 通过单击“立即下载”,下载源码包。 | |
| 39 | # To ONNX | 39 | |
| 40 | python3.7.5 pthtar2onnx.py | 40 | # 准备训练环境 |
| 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 | |||
| 67 | 1. 获取数据集。 | ||
| 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 | |||
| 104 | 2. 数据预处理。 | ||
| 105 | - 在pycls/datasets/loader.py中修改数据集的路径,你可以将变量_DATA_DIR修改为你的imagenet数据集的路径。 | ||
| 106 | |||
| 107 | |||
| 108 | # 开始训练 | ||
| 109 | |||
| 110 | ## 训练模型 | ||
| 111 | |||
| 112 | 1. 进入解压后的源码包根目录。 | ||
| 113 | |||
| 114 | ``` | ||
| 115 | cd /${模型文件夹名称} | ||
| 116 | ``` | ||
| 117 | |||
| 118 | 2. 运行训练脚本。 | ||
| 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 | # 版本说明 | ||
| 165 | 2022.08.01:更新pytorch1.8版本,重新发布。 | ||
| 166 | |||
| 167 | ## 已知问题 | ||
| 168 | 无。 | ||
| 169 | |||
| 170 | |||
| 171 | |||
| 172 | |||
| 173 | |||
| 174 | |||
| @@ -41,7 +41,7 @@ fi | |||
| 41 | 41 | ||
| 42 | # 数据集软链到脚本内部 | 42 | # 数据集软链到脚本内部 |
| 43 | cur_path=`pwd` | 43 | cur_path=`pwd` |
| 44 | default_data_path=${cur_path}/pycls/datasets/data/ | 44 | default_data_path=${cur_path}/pycls/datasets/data |
| 45 | rm -rf ${default_data_path}/imagenet | 45 | rm -rf ${default_data_path}/imagenet |
| 46 | ln -s ${data_path} ${default_data_path}/imagenet | 46 | ln -s ${data_path} ${default_data_path}/imagenet |
| 47 | 47 | ||
| @@ -49,7 +49,7 @@ fi | |||
| 49 | 49 | ||
| 50 | # 数据集软链到脚本内 | 50 | # 数据集软链到脚本内 |
| 51 | cur_path=`pwd` | 51 | cur_path=`pwd` |
| 52 | default_data_path=${cur_path}/pycls/datasets/data/ | 52 | default_data_path=${cur_path}/pycls/datasets/data |
| 53 | rm -rf ${default_data_path}/imagenet | 53 | rm -rf ${default_data_path}/imagenet |
| 54 | ln -s ${data_path} ${default_data_path}/imagenet | 54 | ln -s ${data_path} ${default_data_path}/imagenet |
| 55 | 55 | ||
| @@ -33,7 +33,7 @@ fi | |||
| 33 | 33 | ||
| 34 | # 数据集软链到脚本内部 | 34 | # 数据集软链到脚本内部 |
| 35 | cur_path=`pwd` | 35 | cur_path=`pwd` |
| 36 | default_data_path=${cur_path}/pycls/datasets/data/ | 36 | default_data_path=${cur_path}/pycls/datasets/data |
| 37 | rm -rf ${default_data_path}/imagenet | 37 | rm -rf ${default_data_path}/imagenet |
| 38 | ln -s ${data_path} ${default_data_path}/imagenet | 38 | ln -s ${data_path} ${default_data_path}/imagenet |
| 39 | 39 | ||
| @@ -49,7 +49,7 @@ fi | |||
| 49 | 49 | ||
| 50 | # 数据集软链到脚本内 | 50 | # 数据集软链到脚本内 |
| 51 | cur_path=`pwd` | 51 | cur_path=`pwd` |
| 52 | default_data_path=${cur_path}/pycls/datasets/data/ | 52 | default_data_path=${cur_path}/pycls/datasets/data |
| 53 | rm -rf ${default_data_path}/imagenet | 53 | rm -rf ${default_data_path}/imagenet |
| 54 | ln -s ${data_path} ${default_data_path}/imagenet | 54 | ln -s ${data_path} ${default_data_path}/imagenet |
| 55 | 55 | ||
| @@ -33,7 +33,7 @@ fi | |||
| 33 | 33 | ||
| 34 | # 数据集软链到脚本内部 | 34 | # 数据集软链到脚本内部 |
| 35 | cur_path=`pwd` | 35 | cur_path=`pwd` |
| 36 | default_data_path=${cur_path}/pycls/datasets/data/ | 36 | default_data_path=${cur_path}/pycls/datasets/data |
| 37 | rm -rf ${default_data_path}/imagenet | 37 | rm -rf ${default_data_path}/imagenet |
| 38 | ln -s ${data_path} ${default_data_path}/imagenet | 38 | ln -s ${data_path} ${default_data_path}/imagenet |
| 39 | 39 | ||
| @@ -29,6 +29,8 @@ import pycls.core.trainer as trainer | |||
| 29 | from pycls.core.config import cfg | 29 | from pycls.core.config import cfg |
| 30 | import argparse,sys,os,torch | 30 | import argparse,sys,os,torch |
| 31 | import torch | 31 | import torch |
| 32 | if torch.__version__>= '1.8': | ||
| 33 | import torch_npu | ||
| 32 | 34 | ||
| 33 | def init_process_group(proc_rank, world_size, device_type="npu", port="29588"): | 35 | def init_process_group(proc_rank, world_size, device_type="npu", port="29588"): |
| 34 | """Initializes the default process group.""" | 36 | """Initializes the default process group.""" |