You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 38 kB

5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. # Contents
  2. - [ResNet Description](#resnet-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Features](#features)
  6. - [Mixed Precision](#mixed-precision)
  7. - [Environment Requirements](#environment-requirements)
  8. - [Quick Start](#quick-start)
  9. - [Script Description](#script-description)
  10. - [Script and Sample Code](#script-and-sample-code)
  11. - [Script Parameters](#script-parameters)
  12. - [Training Process](#training-process)
  13. - [Evaluation Process](#evaluation-process)
  14. - [Inference Process](#inference-process)
  15. - [Export MindIR](#export-mindir)
  16. - [Infer on Ascend310](#infer-on-ascend310)
  17. - [result](#result)
  18. - [Model Description](#model-description)
  19. - [Performance](#performance)
  20. - [Evaluation Performance](#evaluation-performance)
  21. - [Inference Performance](#inference-performance)
  22. - [Description of Random Situation](#description-of-random-situation)
  23. - [ModelZoo Homepage](#modelzoo-homepage)
  24. # [ResNet Description](#contents)
  25. ## Description
  26. ResNet (residual neural network) was proposed by Kaiming He and other four Chinese of Microsoft Research Institute. Through the use of ResNet unit, it successfully trained 152 layers of neural network, and won the championship in ilsvrc2015. The error rate on top 5 was 3.57%, and the parameter quantity was lower than vggnet, so the effect was very outstanding. Traditional convolution network or full connection network will have more or less information loss. At the same time, it will lead to the disappearance or explosion of gradient, which leads to the failure of deep network training. ResNet solves this problem to a certain extent. By passing the input information to the output, the integrity of the information is protected. The whole network only needs to learn the part of the difference between input and output, which simplifies the learning objectives and difficulties.The structure of ResNet can accelerate the training of neural network very quickly, and the accuracy of the model is also greatly improved. At the same time, ResNet is very popular, even can be directly used in the concept net network.
  27. These are examples of training ResNet18/ResNet50/ResNet101/SE-ResNet50 with CIFAR-10/ImageNet2012 dataset in MindSpore.ResNet50 and ResNet101 can reference [paper 1](https://arxiv.org/pdf/1512.03385.pdf) below, and SE-ResNet50 is a variant of ResNet50 which reference [paper 2](https://arxiv.org/abs/1709.01507) and [paper 3](https://arxiv.org/abs/1812.01187) below, Training SE-ResNet50 for just 24 epochs using 8 Ascend 910, we can reach top-1 accuracy of 75.9%.(Training ResNet101 with dataset CIFAR-10 and SE-ResNet50 with CIFAR-10 is not supported yet.)
  28. ## Paper
  29. 1.[paper](https://arxiv.org/pdf/1512.03385.pdf):Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun. "Deep Residual Learning for Image Recognition"
  30. 2.[paper](https://arxiv.org/abs/1709.01507):Jie Hu, Li Shen, Samuel Albanie, Gang Sun, Enhua Wu. "Squeeze-and-Excitation Networks"
  31. 3.[paper](https://arxiv.org/abs/1812.01187):Tong He, Zhi Zhang, Hang Zhang, Zhongyue Zhang, Junyuan Xie, Mu Li. "Bag of Tricks for Image Classification with Convolutional Neural Networks"
  32. # [Model Architecture](#contents)
  33. The overall network architecture of ResNet is show below:
  34. [Link](https://arxiv.org/pdf/1512.03385.pdf)
  35. # [Dataset](#contents)
  36. Dataset used: [CIFAR-10](<http://www.cs.toronto.edu/~kriz/cifar.html>)
  37. - Dataset size:60,000 32*32 colorful images in 10 classes
  38. - Train:50,000 images
  39. - Test: 10,000 images
  40. - Data format:binary files
  41. - Note:Data will be processed in dataset.py
  42. - Download the dataset, the directory structure is as follows:
  43. ```bash
  44. ├─cifar-10-batches-bin
  45. └─cifar-10-verify-bin
  46. ```
  47. Dataset used: [ImageNet2012](http://www.image-net.org/)
  48. - Dataset size 224*224 colorful images in 1000 classes
  49. - Train:1,281,167 images
  50. - Test: 50,000 images
  51. - Data format:jpeg
  52. - Note:Data will be processed in dataset.py
  53. - Download the dataset, the directory structure is as follows:
  54. ```bash
  55. └─dataset
  56. ├─ilsvrc # train dataset
  57. └─validation_preprocess # evaluate dataset
  58. ```
  59. # [Features](#contents)
  60. ## Mixed Precision
  61. The [mixed precision](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/enable_mixed_precision.html) training method accelerates the deep learning neural network training process by using both the single-precision and half-precision data types, and maintains the network precision achieved by the single-precision training at the same time. Mixed precision training can accelerate the computation process, reduce memory usage, and enable a larger model or batch size to be trained on specific hardware.
  62. For FP16 operators, if the input data type is FP32, the backend of MindSpore will automatically handle it with reduced precision. Users could check the reduced-precision operators by enabling INFO log and then searching ‘reduce precision’.
  63. # [Environment Requirements](#contents)
  64. - Hardware(Ascend/GPU/CPU)
  65. - Prepare hardware environment with Ascend, GPU or CPU processor.
  66. - Framework
  67. - [MindSpore](https://www.mindspore.cn/install/en)
  68. - For more information, please check the resources below:
  69. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  70. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  71. # [Quick Start](#contents)
  72. After installing MindSpore via the official website, you can start training and evaluation as follows:
  73. - Running on Ascend
  74. ```bash
  75. # distributed training
  76. Usage: bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  77. # standalone training
  78. Usage: bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
  79. [PRETRAINED_CKPT_PATH](optional)
  80. # run evaluation example
  81. Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  82. ```
  83. - Running on GPU
  84. ```bash
  85. # distributed training example
  86. bash run_distribute_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  87. # standalone training example
  88. bash run_standalone_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  89. # infer example
  90. bash run_eval_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  91. # gpu benchmark example
  92. bash run_gpu_resnet_benchmark.sh [DATASET_PATH] [BATCH_SIZE](optional) [DTYPE](optional) [DEVICE_NUM](optional) [SAVE_CKPT](optional) [SAVE_PATH](optional)
  93. ```
  94. - Running on CPU
  95. ```bash
  96. # standalone training example
  97. python train.py --net=[resnet50|resnet101] --dataset=[cifar10|imagenet2012] --device_target=CPU --dataset_path=[DATASET_PATH] --pre_trained=[CHECKPOINT_PATH](optional)
  98. # infer example
  99. python eval.py --net=[resnet50|resnet101] --dataset=[cifar10|imagenet2012] --dataset_path=[DATASET_PATH] --checkpoint_path=[CHECKPOINT_PATH] --device_target=CPU
  100. ```
  101. # [Script Description](#contents)
  102. ## [Script and Sample Code](#contents)
  103. ```shell
  104. .
  105. └──resnet
  106. ├── README.md
  107. ├── scripts
  108. ├── run_distribute_train.sh # launch ascend distributed training(8 pcs)
  109. ├── run_parameter_server_train.sh # launch ascend parameter server training(8 pcs)
  110. ├── run_eval.sh # launch ascend evaluation
  111. ├── run_standalone_train.sh # launch ascend standalone training(1 pcs)
  112. ├── run_distribute_train_gpu.sh # launch gpu distributed training(8 pcs)
  113. ├── run_parameter_server_train_gpu.sh # launch gpu parameter server training(8 pcs)
  114. ├── run_eval_gpu.sh # launch gpu evaluation
  115. ├── run_standalone_train_gpu.sh # launch gpu standalone training(1 pcs)
  116. ├── run_gpu_resnet_benchmark.sh # launch gpu benchmark train for resnet50 with imagenet2012
  117. └── run_eval_gpu_resnet_benckmark.sh # launch gpu benchmark eval for resnet50 with imagenet2012
  118. ├── src
  119. ├── config.py # parameter configuration
  120. ├── dataset.py # data preprocessing
  121. ├─ eval_callback.py # evaluation callback while training
  122. ├── CrossEntropySmooth.py # loss definition for ImageNet2012 dataset
  123. ├── lr_generator.py # generate learning rate for each step
  124. ├── resnet.py # resnet backbone, including resnet50 and resnet101 and se-resnet50
  125. └── resnet_gpu_benchmark.py # resnet50 for GPU benchmark
  126. ├── export.py # export model for inference
  127. ├── mindspore_hub_conf.py # mindspore hub interface
  128. ├── eval.py # eval net
  129. ├── train.py # train net
  130. └── gpu_resent_benchmark.py # GPU benchmark for resnet50
  131. ```
  132. ## [Script Parameters](#contents)
  133. Parameters for both training and evaluation can be set in config.py.
  134. - Config for ResNet18 and ResNet50, CIFAR-10 dataset
  135. ```bash
  136. "class_num": 10, # dataset class num
  137. "batch_size": 32, # batch size of input tensor
  138. "loss_scale": 1024, # loss scale
  139. "momentum": 0.9, # momentum
  140. "weight_decay": 1e-4, # weight decay
  141. "epoch_size": 90, # only valid for taining, which is always 1 for inference
  142. "pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size
  143. "save_checkpoint": True, # whether save checkpoint or not
  144. "save_checkpoint_epochs": 5, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last step
  145. "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint
  146. "save_checkpoint_path": "./", # path to save checkpoint
  147. "warmup_epochs": 5, # number of warmup epoch
  148. "lr_decay_mode": "poly" # decay mode can be selected in steps, ploy and default
  149. "lr_init": 0.01, # initial learning rate
  150. "lr_end": 0.00001, # final learning rate
  151. "lr_max": 0.1, # maximum learning rate
  152. ```
  153. - Config for ResNet18 and ResNet50, ImageNet2012 dataset
  154. ```bash
  155. "class_num": 1001, # dataset class number
  156. "batch_size": 256, # batch size of input tensor
  157. "loss_scale": 1024, # loss scale
  158. "momentum": 0.9, # momentum optimizer
  159. "weight_decay": 1e-4, # weight decay
  160. "epoch_size": 90, # only valid for taining, which is always 1 for inference
  161. "pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size
  162. "save_checkpoint": True, # whether save checkpoint or not
  163. "save_checkpoint_epochs": 5, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch
  164. "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint
  165. "save_checkpoint_path": "./", # path to save checkpoint relative to the executed path
  166. "warmup_epochs": 0, # number of warmup epoch
  167. "lr_decay_mode": "Linear", # decay mode for generating learning rate
  168. "use_label_smooth": True, # label smooth
  169. "label_smooth_factor": 0.1, # label smooth factor
  170. "lr_init": 0, # initial learning rate
  171. "lr_max": 0.8, # maximum learning rate
  172. "lr_end": 0.0, # minimum learning rate
  173. ```
  174. - Config for ResNet101, ImageNet2012 dataset
  175. ```bash
  176. "class_num": 1001, # dataset class number
  177. "batch_size": 32, # batch size of input tensor
  178. "loss_scale": 1024, # loss scale
  179. "momentum": 0.9, # momentum optimizer
  180. "weight_decay": 1e-4, # weight decay
  181. "epoch_size": 120, # epoch size for training
  182. "pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size
  183. "save_checkpoint": True, # whether save checkpoint or not
  184. "save_checkpoint_epochs": 5, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch
  185. "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint
  186. "save_checkpoint_path": "./", # path to save checkpoint relative to the executed path
  187. "warmup_epochs": 0, # number of warmup epoch
  188. "lr_decay_mode": "cosine" # decay mode for generating learning rate
  189. "use_label_smooth": True, # label_smooth
  190. "label_smooth_factor": 0.1, # label_smooth_factor
  191. "lr": 0.1 # base learning rate
  192. ```
  193. - Config for SE-ResNet50, ImageNet2012 dataset
  194. ```bash
  195. "class_num": 1001, # dataset class number
  196. "batch_size": 32, # batch size of input tensor
  197. "loss_scale": 1024, # loss scale
  198. "momentum": 0.9, # momentum optimizer
  199. "weight_decay": 1e-4, # weight decay
  200. "epoch_size": 28 , # epoch size for creating learning rate
  201. "train_epoch_size": 24 # actual train epoch size
  202. "pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size
  203. "save_checkpoint": True, # whether save checkpoint or not
  204. "save_checkpoint_epochs": 4, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch
  205. "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint
  206. "save_checkpoint_path": "./", # path to save checkpoint relative to the executed path
  207. "warmup_epochs": 3, # number of warmup epoch
  208. "lr_decay_mode": "cosine" # decay mode for generating learning rate
  209. "use_label_smooth": True, # label_smooth
  210. "label_smooth_factor": 0.1, # label_smooth_factor
  211. "lr_init": 0.0, # initial learning rate
  212. "lr_max": 0.3, # maximum learning rate
  213. "lr_end": 0.0001, # end learning rate
  214. ```
  215. ## [Training Process](#contents)
  216. ### Usage
  217. #### Running on Ascend
  218. ```bash
  219. # distributed training
  220. Usage: bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  221. # standalone training
  222. Usage: bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
  223. [PRETRAINED_CKPT_PATH](optional)
  224. # run evaluation example
  225. Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  226. ```
  227. For distributed training, a hccl configuration file with JSON format needs to be created in advance.
  228. Please follow the instructions in the link [hccn_tools](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools).
  229. Training result will be stored in the example path, whose folder name begins with "train" or "train_parallel". Under this, you can find checkpoint file together with result like the following in log.
  230. If you want to change device_id for standalone training, you can set environment variable `export DEVICE_ID=x` or set `device_id=x` in context.
  231. #### Running on GPU
  232. ```bash
  233. # distributed training example
  234. bash run_distribute_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  235. # standalone training example
  236. bash run_standalone_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  237. # infer example
  238. bash run_eval_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  239. # gpu benchmark training example
  240. bash run_gpu_resnet_benchmark.sh [DATASET_PATH] [BATCH_SIZE](optional) [DTYPE](optional) [DEVICE_NUM](optional) [SAVE_CKPT](optional) [SAVE_PATH](optional)
  241. # gpu benchmark infer example
  242. bash run_eval_gpu_resnet_benchmark.sh [DATASET_PATH] [CKPT_PATH] [BATCH_SIZE](optional) [DTYPE](optional)
  243. ```
  244. For distributed training, a hostfile configuration needs to be created in advance.
  245. Please follow the instructions in the link [GPU-Multi-Host](https://www.mindspore.cn/tutorial/training/zh-CN/r1.0/advanced_use/distributed_training_gpu.html).
  246. #### Running parameter server mode training
  247. - Parameter server training Ascend example
  248. ```bash
  249. bash run_parameter_server_train.sh [resnet18|resnet50|resnet101] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  250. ```
  251. - Parameter server training GPU example
  252. ```bash
  253. bash run_parameter_server_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  254. ```
  255. #### Evaluation while training
  256. You can add `run_eval` to start shell and set it True, if you want evaluation while training. And you can set argument option: `eval_dataset_path`, `save_best_ckpt`, `eval_start_epoch`, `eval_interval` when `run_eval` is True.
  257. ### Result
  258. - Training ResNet18 with CIFAR-10 dataset
  259. ```bash
  260. # distribute training result(8 pcs)
  261. epoch: 1 step: 195, loss is 1.5783054
  262. epoch: 2 step: 195, loss is 1.0682616
  263. epoch: 3 step: 195, loss is 0.8836588
  264. epoch: 4 step: 195, loss is 0.36090446
  265. epoch: 5 step: 195, loss is 0.80853784
  266. ...
  267. ```
  268. - Training ResNet18 with ImageNet2012 dataset
  269. ```bash
  270. # distribute training result(8 pcs)
  271. epoch: 1 step: 625, loss is 4.757934
  272. epoch: 2 step: 625, loss is 4.0891967
  273. epoch: 3 step: 625, loss is 3.9131956
  274. epoch: 4 step: 625, loss is 3.5302577
  275. epoch: 5 step: 625, loss is 3.597817
  276. ...
  277. ```
  278. - Training ResNet50 with CIFAR-10 dataset
  279. ```bash
  280. # distribute training result(8 pcs)
  281. epoch: 1 step: 195, loss is 1.9601055
  282. epoch: 2 step: 195, loss is 1.8555021
  283. epoch: 3 step: 195, loss is 1.6707983
  284. epoch: 4 step: 195, loss is 1.8162166
  285. epoch: 5 step: 195, loss is 1.393667
  286. ...
  287. ```
  288. - Training ResNet50 with ImageNet2012 dataset
  289. ```bash
  290. # distribute training result(8 pcs)
  291. epoch: 1 step: 5004, loss is 4.8995576
  292. epoch: 2 step: 5004, loss is 3.9235563
  293. epoch: 3 step: 5004, loss is 3.833077
  294. epoch: 4 step: 5004, loss is 3.2795618
  295. epoch: 5 step: 5004, loss is 3.1978393
  296. ...
  297. ```
  298. - Training ResNet101 with ImageNet2012 dataset
  299. ```bash
  300. # distribute training result(8 pcs)
  301. epoch: 1 step: 5004, loss is 4.805483
  302. epoch: 2 step: 5004, loss is 3.2121816
  303. epoch: 3 step: 5004, loss is 3.429647
  304. epoch: 4 step: 5004, loss is 3.3667371
  305. epoch: 5 step: 5004, loss is 3.1718972
  306. ...
  307. ```
  308. - Training SE-ResNet50 with ImageNet2012 dataset
  309. ```bash
  310. # distribute training result(8 pcs)
  311. epoch: 1 step: 5004, loss is 5.1779146
  312. epoch: 2 step: 5004, loss is 4.139395
  313. epoch: 3 step: 5004, loss is 3.9240637
  314. epoch: 4 step: 5004, loss is 3.5011306
  315. epoch: 5 step: 5004, loss is 3.3501816
  316. ...
  317. ```
  318. - GPU Benchmark of ResNet50 with ImageNet2012 dataset
  319. ```bash
  320. # ========START RESNET50 GPU BENCHMARK========
  321. epoch: [0/1] step: [20/5004], loss is 6.940182 Epoch time: 12416.098 ms, fps: 412 img/sec.
  322. epoch: [0/1] step: [40/5004], loss is 7.078993Epoch time: 3438.972 ms, fps: 1488 img/sec.
  323. epoch: [0/1] step: [60/5004], loss is 7.559594Epoch time: 3431.516 ms, fps: 1492 img/sec.
  324. epoch: [0/1] step: [80/5004], loss is 6.920937Epoch time: 3435.777 ms, fps: 1490 img/sec.
  325. epoch: [0/1] step: [100/5004], loss is 6.814013Epoch time: 3437.154 ms, fps: 1489 img/sec.
  326. ...
  327. ```
  328. ## [Evaluation Process](#contents)
  329. ### Usage
  330. #### Running on Ascend
  331. ```bash
  332. # evaluation
  333. Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  334. ```
  335. ```bash
  336. # evaluation example
  337. bash run_eval.sh resnet50 cifar10 ~/cifar10-10-verify-bin ~/resnet50_cifar10/train_parallel0/resnet-90_195.ckpt
  338. ```
  339. > checkpoint can be produced in training process.
  340. #### Running on GPU
  341. ```bash
  342. bash run_eval_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  343. ```
  344. ### Result
  345. Evaluation result will be stored in the example path, whose folder name is "eval". Under this, you can find result like the following in log.
  346. - Evaluating ResNet18 with CIFAR-10 dataset
  347. ```bash
  348. result: {'acc': 0.9402043269230769} ckpt=~/resnet50_cifar10/train_parallel0/resnet-90_195.ckpt
  349. ```
  350. - Evaluating ResNet18 with ImageNet2012 dataset
  351. ```bash
  352. result: {'acc': 0.7053685897435897} ckpt=train_parallel0/resnet-90_5004.ckpt
  353. ```
  354. - Evaluating ResNet50 with CIFAR-10 dataset
  355. ```bash
  356. result: {'acc': 0.91446314102564111} ckpt=~/resnet50_cifar10/train_parallel0/resnet-90_195.ckpt
  357. ```
  358. - Evaluating ResNet50 with ImageNet2012 dataset
  359. ```bash
  360. result: {'acc': 0.7671054737516005} ckpt=train_parallel0/resnet-90_5004.ckpt
  361. ```
  362. - Evaluating ResNet101 with ImageNet2012 dataset
  363. ```bash
  364. result: {'top_5_accuracy': 0.9429417413572343, 'top_1_accuracy': 0.7853513124199744} ckpt=train_parallel0/resnet-120_5004.ckpt
  365. ```
  366. - Evaluating SE-ResNet50 with ImageNet2012 dataset
  367. ```bash
  368. result: {'top_5_accuracy': 0.9342589628681178, 'top_1_accuracy': 0.768065781049936} ckpt=train_parallel0/resnet-24_5004.ckpt
  369. ```
  370. ## Inference Process
  371. ### [Export MindIR](#contents)
  372. ```shell
  373. python export.py --ckpt_file [CKPT_PATH] --file_name [FILE_NAME] --file_format [FILE_FORMAT]
  374. ```
  375. The ckpt_file parameter is required,
  376. `EXPORT_FORMAT` should be in ["AIR", "MINDIR"]
  377. ### Infer on Ascend310
  378. Before performing inference, the mindir file must bu exported by `export.py` script. We only provide an example of inference using MINDIR model.
  379. Current batch_Size can only be set to 1. The precision calculation process needs about 70G+ memory space, otherwise the process will be killed for execeeding memory limits.
  380. ```shell
  381. # Ascend310 inference
  382. bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DEVICE_ID]
  383. ```
  384. - `DEVICE_ID` is optional, default value is 0.
  385. ### result
  386. Inference result is saved in current path, you can find result like this in acc.log file.
  387. ```bash
  388. top1_accuracy:70.42, top5_accuracy:89.7
  389. ```
  390. # [Model Description](#contents)
  391. ## [Performance](#contents)
  392. ### Evaluation Performance
  393. #### ResNet18 on CIFAR-10
  394. | Parameters | Ascend 910 |
  395. | -------------------------- | -------------------------------------- |
  396. | Model Version | ResNet18 |
  397. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
  398. | uploaded Date | 02/25/2021 (month/day/year) |
  399. | MindSpore Version | 1.1.1-alpha |
  400. | Dataset | CIFAR-10 |
  401. | Training Parameters | epoch=90, steps per epoch=195, batch_size = 32 |
  402. | Optimizer | Momentum |
  403. | Loss Function | Softmax Cross Entropy |
  404. | outputs | probability |
  405. | Loss | 0.0002519517 |
  406. | Speed | 13 ms/step(8pcs) |
  407. | Total time | 4 mins |
  408. | Parameters (M) | 11.2 |
  409. | Checkpoint for Fine tuning | 86M (.ckpt file) |
  410. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
  411. #### ResNet18 on ImageNet2012
  412. | Parameters | Ascend 910 |
  413. | -------------------------- | -------------------------------------- |
  414. | Model Version | ResNet18 |
  415. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
  416. | uploaded Date | 02/25/2021 (month/day/year) ; |
  417. | MindSpore Version | 1.1.1-alpha |
  418. | Dataset | ImageNet2012 |
  419. | Training Parameters | epoch=90, steps per epoch=626, batch_size = 256 |
  420. | Optimizer | Momentum |
  421. | Loss Function | Softmax Cross Entropy |
  422. | outputs | probability |
  423. | Loss | 2.15702 |
  424. | Speed | 110ms/step(8pcs) (may need to set_numa_enbale in dataset.py) |
  425. | Total time | 110 mins |
  426. | Parameters (M) | 11.7 |
  427. | Checkpoint for Fine tuning | 90M (.ckpt file) |
  428. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
  429. #### ResNet50 on CIFAR-10
  430. | Parameters | Ascend 910 | GPU |
  431. | -------------------------- | -------------------------------------- |---------------------------------- |
  432. | Model Version | ResNet50-v1.5 |ResNet50-v1.5|
  433. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 | GPU(Tesla V100 SXM2),CPU 2.1GHz 24cores,Memory 128G
  434. | uploaded Date | 04/01/2020 (month/day/year) | 08/01/2020 (month/day/year)
  435. | MindSpore Version | 0.1.0-alpha |0.6.0-alpha |
  436. | Dataset | CIFAR-10 | CIFAR-10
  437. | Training Parameters | epoch=90, steps per epoch=195, batch_size = 32 |epoch=90, steps per epoch=195, batch_size = 32 |
  438. | Optimizer | Momentum |Momentum|
  439. | Loss Function | Softmax Cross Entropy |Softmax Cross Entropy |
  440. | outputs | probability | probability |
  441. | Loss | 0.000356 | 0.000716 |
  442. | Speed | 18.4ms/step(8pcs) |69ms/step(8pcs)|
  443. | Total time | 6 mins | 20.2 mins|
  444. | Parameters (M) | 25.5 | 25.5 |
  445. | Checkpoint for Fine tuning | 179.7M (.ckpt file) |179.7M (.ckpt file)|
  446. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
  447. #### ResNet50 on ImageNet2012
  448. | Parameters | Ascend 910 | GPU |
  449. | -------------------------- | -------------------------------------- |---------------------------------- |
  450. | Model Version | ResNet50-v1.5 |ResNet50-v1.5|
  451. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 | GPU(Tesla V100 SXM2),CPU 2.1GHz 24cores,Memory 128G
  452. | uploaded Date | 04/01/2020 (month/day/year) ; | 08/01/2020 (month/day/year)
  453. | MindSpore Version | 0.1.0-alpha |0.6.0-alpha |
  454. | Dataset | ImageNet2012 | ImageNet2012|
  455. | Training Parameters | epoch=90, steps per epoch=626, batch_size = 256 |epoch=90, steps per epoch=626, batch_size = 256 |
  456. | Optimizer | Momentum |Momentum|
  457. | Loss Function | Softmax Cross Entropy |Softmax Cross Entropy |
  458. | outputs | probability | probability |
  459. | Loss | 1.8464266 | 1.9023 |
  460. | Speed | 118ms/step(8pcs) |270ms/step(8pcs)|
  461. | Total time | 114 mins | 260 mins|
  462. | Parameters (M) | 25.5 | 25.5 |
  463. | Checkpoint for Fine tuning | 197M (.ckpt file) |197M (.ckpt file) |
  464. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
  465. #### ResNet101 on ImageNet2012
  466. | Parameters | Ascend 910 | GPU |
  467. | -------------------------- | -------------------------------------- |---------------------------------- |
  468. | Model Version | ResNet101 |ResNet101|
  469. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 | GPU(Tesla V100 SXM2),CPU 2.1GHz 24cores,Memory 128G
  470. | uploaded Date | 04/01/2020 (month/day/year) | 08/01/2020 (month/day/year)
  471. | MindSpore Version | 0.1.0-alpha |0.6.0-alpha |
  472. | Dataset | ImageNet2012 | ImageNet2012|
  473. | Training Parameters | epoch=120, steps per epoch=5004, batch_size = 32 |epoch=120, steps per epoch=5004, batch_size = 32 |
  474. | Optimizer | Momentum |Momentum|
  475. | Loss Function | Softmax Cross Entropy |Softmax Cross Entropy |
  476. | outputs | probability | probability |
  477. | Loss | 1.6453942 | 1.7023412 |
  478. | Speed | 30.3ms/step(8pcs) |108.6ms/step(8pcs)|
  479. | Total time | 301 mins | 1100 mins|
  480. | Parameters (M) | 44.6 | 44.6 |
  481. | Checkpoint for Fine tuning | 343M (.ckpt file) |343M (.ckpt file) |
  482. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
  483. #### SE-ResNet50 on ImageNet2012
  484. | Parameters | Ascend 910
  485. | -------------------------- | ------------------------------------------------------------------------ |
  486. | Model Version | SE-ResNet50 |
  487. | Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
  488. | uploaded Date | 08/16/2020 (month/day/year) |
  489. | MindSpore Version | 0.7.0-alpha |
  490. | Dataset | ImageNet2012 |
  491. | Training Parameters | epoch=24, steps per epoch=5004, batch_size = 32 |
  492. | Optimizer | Momentum |
  493. | Loss Function | Softmax Cross Entropy |
  494. | outputs | probability |
  495. | Loss | 1.754404 |
  496. | Speed | 24.6ms/step(8pcs) |
  497. | Total time | 49.3 mins |
  498. | Parameters (M) | 25.5 |
  499. | Checkpoint for Fine tuning | 215.9M (.ckpt file) |
  500. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
  501. ### Inference Performance
  502. #### ResNet18 on CIFAR-10
  503. | Parameters | Ascend |
  504. | ------------------- | --------------------------- |
  505. | Model Version | ResNet18 |
  506. | Resource | Ascend 910; OS Euler2.8 |
  507. | Uploaded Date | 02/25/2021 (month/day/year) |
  508. | MindSpore Version | 1.1.1-alpha |
  509. | Dataset | CIFAR-10 |
  510. | batch_size | 32 |
  511. | outputs | probability |
  512. | Accuracy | 94.02% |
  513. | Model for inference | 43M (.air file) |
  514. #### ResNet18 on ImageNet2012
  515. | Parameters | Ascend |
  516. | ------------------- | --------------------------- |
  517. | Model Version | ResNet18 |
  518. | Resource | Ascend 910; OS Euler2.8 |
  519. | Uploaded Date | 02/25/2021 (month/day/year) |
  520. | MindSpore Version | 1.1.1-alpha |
  521. | Dataset | ImageNet2012 |
  522. | batch_size | 256 |
  523. | outputs | probability |
  524. | Accuracy | 70.53% |
  525. | Model for inference | 45M (.air file) |
  526. #### ResNet50 on CIFAR-10
  527. | Parameters | Ascend | GPU |
  528. | ------------------- | --------------------------- | --------------------------- |
  529. | Model Version | ResNet50-v1.5 | ResNet50-v1.5 |
  530. | Resource | Ascend 910; OS Euler2.8 | GPU |
  531. | Uploaded Date | 04/01/2020 (month/day/year) | 08/01/2020 (month/day/year) |
  532. | MindSpore Version | 0.1.0-alpha | 0.6.0-alpha |
  533. | Dataset | CIFAR-10 | CIFAR-10 |
  534. | batch_size | 32 | 32 |
  535. | outputs | probability | probability |
  536. | Accuracy | 91.44% | 91.37% |
  537. | Model for inference | 91M (.air file) | |
  538. #### ResNet50 on ImageNet2012
  539. | Parameters | Ascend | GPU |
  540. | ------------------- | --------------------------- | --------------------------- |
  541. | Model Version | ResNet50-v1.5 | ResNet50-v1.5 |
  542. | Resource | Ascend 910; OS Euler2.8 | GPU |
  543. | Uploaded Date | 04/01/2020 (month/day/year) | 08/01/2020 (month/day/year) |
  544. | MindSpore Version | 0.1.0-alpha | 0.6.0-alpha |
  545. | Dataset | ImageNet2012 | ImageNet2012 |
  546. | batch_size | 256 | 256 |
  547. | outputs | probability | probability |
  548. | Accuracy | 76.70% | 76.74% |
  549. | Model for inference | 98M (.air file) | |
  550. #### ResNet101 on ImageNet2012
  551. | Parameters | Ascend | GPU |
  552. | ------------------- | --------------------------- | --------------------------- |
  553. | Model Version | ResNet101 | ResNet101 |
  554. | Resource | Ascend 910; OS Euler2.8 | GPU |
  555. | Uploaded Date | 04/01/2020 (month/day/year) | 08/01/2020 (month/day/year) |
  556. | MindSpore Version | 0.1.0-alpha | 0.6.0-alpha |
  557. | Dataset | ImageNet2012 | ImageNet2012 |
  558. | batch_size | 32 | 32 |
  559. | outputs | probability | probability |
  560. | Accuracy | 78.53% | 78.64% |
  561. | Model for inference | 171M (.air file) | |
  562. #### SE-ResNet50 on ImageNet2012
  563. | Parameters | Ascend |
  564. | ------------------- | --------------------------- |
  565. | Model Version | SE-ResNet50 |
  566. | Resource | Ascend 910; OS Euler2.8 |
  567. | Uploaded Date | 08/16/2020 (month/day/year) |
  568. | MindSpore Version | 0.7.0-alpha |
  569. | Dataset | ImageNet2012 |
  570. | batch_size | 32 |
  571. | outputs | probability |
  572. | Accuracy | 76.80% |
  573. | Model for inference | 109M (.air file) |
  574. # [Description of Random Situation](#contents)
  575. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
  576. # [ModelZoo Homepage](#contents)
  577. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).