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 9.6 kB

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
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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. # Contents
  2. - [ResNet50 Description](#resnet50-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Features](#features)
  6. - [Mixed Precision](#mixed-precision)
  7. - [Environment Requirements](#environment-requirements)
  8. - [Script Description](#script-description)
  9. - [Script and Sample Code](#script-and-sample-code)
  10. - [Script Parameters](#script-parameters)
  11. - [Training Process](#training-process)
  12. - [Evaluation Process](#evaluation-process)
  13. - [Model Description](#model-description)
  14. - [Performance](#performance)
  15. - [Evaluation Performance](#evaluation-performance)
  16. - [Inference Performance](#inference-performance)
  17. - [Description of Random Situation](#description-of-random-situation)
  18. - [ModelZoo Homepage](#modelzoo-homepage)
  19. # [ResNet50 Description](#contents)
  20. ResNet-50 is a convolutional neural network that is 50 layers deep, which can classify ImageNet image to 1000 object categories with 76% accuracy.
  21. [Paper](https://arxiv.org/abs/1512.03385): Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun."Deep Residual Learning for Image Recognition." He, Kaiming , et al. "Deep Residual Learning for Image Recognition." IEEE Conference on Computer Vision & Pattern Recognition IEEE Computer Society, 2016.
  22. This is the quantitative network of ResNet50.
  23. # [Model Architecture](#contents)
  24. The overall network architecture of Resnet50 is show below:
  25. [Link](https://arxiv.org/pdf/1512.03385.pdf)
  26. # [Dataset](#contents)
  27. Dataset used: [ImageNet2012](http://www.image-net.org/)
  28. - Dataset size 224*224 colorful images in 1000 classes
  29. - Train:1,281,167 images
  30. - Test: 50,000 images
  31. - Data format:jpeg
  32. - Note:Data will be processed in dataset.py
  33. - Download the dataset, the directory structure is as follows:
  34. ```python
  35. └─dataset
  36. ├─ilsvrc # train dataset
  37. └─validation_preprocess # evaluate dataset
  38. ```
  39. # [Features](#contents)
  40. ## [Mixed Precision](#contents)
  41. 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 formats, 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.
  42. 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’.
  43. # [Environment Requirements](#contents)
  44. - Hardware:Ascend
  45. - Prepare hardware environment with Ascend.
  46. - Framework
  47. - [MindSpore](https://www.mindspore.cn/install/en)
  48. - For more information, please check the resources below:
  49. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  50. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  51. # [Script description](#contents)
  52. ## [Script and sample code](#contents)
  53. ```python
  54. ├── resnet50_quant
  55. ├── README.md # descriptions about Resnet50-Quant
  56. ├── scripts
  57. │ ├──run_train.sh # shell script for train on Ascend
  58. │ ├──run_infer.sh # shell script for evaluation on Ascend
  59. ├── models
  60. │ ├──resnet_quant.py # define the network model of resnet50-quant
  61. │ ├──resnet_quant_manual.py # define the manually quantized network model of resnet50-quant
  62. ├── src
  63. │ ├──config.py # parameter configuration
  64. │ ├──dataset.py # creating dataset
  65. │ ├──launch.py # start python script
  66. │ ├──lr_generator.py # learning rate config
  67. │ ├──crossentropy.py # define the crossentropy of resnet50-quant
  68. ├── train.py # training script
  69. ├── eval.py # evaluation script
  70. ├── export.py # export script
  71. ```
  72. ## [Script Parameters](#contents)
  73. Parameters for both training and evaluation can be set in config.py
  74. - config for Resnet50-quant, ImageNet2012 dataset
  75. ```python
  76. 'class_num': 10 # the number of classes in the dataset
  77. 'batch_size': 32 # training batch size
  78. 'loss_scale': 1024 # the initial loss_scale value
  79. 'momentum': 0.9 # momentum
  80. 'weight_decay': 1e-4 # weight decay value
  81. 'epoch_size': 120 # total training epochs
  82. 'pretrained_epoch_size': 90 # pretraining epochs of resnet50, which is unquantative network of resnet50_quant
  83. 'data_load_mode': 'original' # the style of loading data into device, support 'original' or 'mindrecord'
  84. 'save_checkpoint':True # whether save checkpoint file after training finish
  85. 'save_checkpoint_epochs': 1 # the step from which start to save checkpoint file.
  86. 'keep_checkpoint_max': 50 # only keep the last keep_checkpoint_max checkpoint
  87. 'save_checkpoint_path': './' # the absolute full path to save the checkpoint file
  88. "warmup_epochs": 0 # number of warmup epochs
  89. 'lr_decay_mode': "cosine" # learning rate decay mode, including steps, steps_decay, cosine or liner
  90. 'use_label_smooth': True # whether use label smooth
  91. 'label_smooth_factor': 0.1 # label smooth factor
  92. 'lr_init': 0 # initial learning rate
  93. 'lr_max': 0.005 # the max learning rate
  94. ```
  95. ## [Training process](#contents)
  96. ### Usage
  97. - Ascend: sh run_train.sh Ascend [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH]\(optional)
  98. ### Launch
  99. ```bash
  100. # training example
  101. Ascend: bash run_train.sh Ascend ~/hccl.json ~/imagenet/train/ ~/pretrained_ckeckpoint
  102. ```
  103. ### Result
  104. Training result will be stored in the example path. Checkpoints will be stored at `./train/device$i/` by default, and training log will be redirected to `./train/device$i/train.log` like following.
  105. ```bash
  106. epoch: 1 step: 5004, loss is 4.8995576
  107. epoch: 2 step: 5004, loss is 3.9235563
  108. epoch: 3 step: 5004, loss is 3.833077
  109. epoch: 4 step: 5004, loss is 3.2795618
  110. epoch: 5 step: 5004, loss is 3.1978393
  111. ```
  112. ## [Evaluation process](#contents)
  113. ### Usage
  114. You can start training using python or shell scripts. The usage of shell scripts as follows:
  115. - Ascend: sh run_infer.sh Ascend [DATASET_PATH] [CHECKPOINT_PATH]
  116. ### Launch
  117. ```bash
  118. # infer example
  119. shell:
  120. Ascend: sh run_infer.sh Ascend ~/imagenet/val/ ~/train/Resnet50-30_5004.ckpt
  121. ```
  122. > checkpoint can be produced in training process.
  123. ### Result
  124. Inference result will be stored in the example path, you can find result like the following in `./eval/infer.log`.
  125. ```bash
  126. result: {'acc': 0.76576314102564111}
  127. ```
  128. # [Model description](#contents)
  129. ## [Performance](#contents)
  130. ### Evaluation Performance
  131. | Parameters | Ascend |
  132. | -------------------------- | ----------------------------------------------------------- |
  133. | Model Version | ResNet50 V1.5 |
  134. | Resource | Ascend 910; CPU 2.60GHz, 56cores; Memory 314G; OS Euler2.8 |
  135. | uploaded Date | 06/06/2020 (month/day/year) |
  136. | MindSpore Version | 0.3.0-alpha |
  137. | Dataset | ImageNet |
  138. | Training Parameters | epoch=30(with pretrained) or 120, steps per epoch=5004, batch_size=32 |
  139. | Optimizer | Momentum |
  140. | Loss Function | Softmax Cross Entropy |
  141. | outputs | probability |
  142. | Loss | 1.8 |
  143. | Speed | 8pcs: 407 ms/step |
  144. | Total time | 8pcs: 17 hours(30 epochs with pretrained) |
  145. | Parameters (M) | 25.5 |
  146. | Checkpoint for Fine tuning | 197M (.ckpt file) |
  147. | Scripts | [resnet50-quant script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet50_quant) |
  148. ### Inference Performance
  149. | Parameters | Ascend |
  150. | ------------------- | --------------------------- |
  151. | Model Version | ResNet50 V1.5 |
  152. | Resource | Ascend 910; CPU 2.60GHz, 56cores; Memory 314G; OS Euler2.8 |
  153. | Uploaded Date | 06/06/2020 (month/day/year) |
  154. | MindSpore Version | 0.3.0-alpha |
  155. | Dataset | ImageNet |
  156. | batch_size | 32 |
  157. | outputs | probability |
  158. | Accuracy | ACC1[76.57%] ACC5[92.90%] |
  159. | Model for inference | 197M (.ckpt file) |
  160. # [Description of Random Situation](#contents)
  161. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
  162. # [ModelZoo Homepage](#contents)
  163. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).