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.8 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
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. ```
  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. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
  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. ```
  71. ## [Script Parameters](#contents)
  72. Parameters for both training and evaluation can be set in config.py
  73. - config for Resnet50-quant, ImageNet2012 dataset
  74. ```python
  75. 'class_num': 10 # the number of classes in the dataset
  76. 'batch_size': 32 # training batch size
  77. 'loss_scale': 1024 # the initial loss_scale value
  78. 'momentum': 0.9 # momentum
  79. 'weight_decay': 1e-4 # weight decay value
  80. 'epoch_size': 120 # total training epochs
  81. 'pretrained_epoch_size': 90 # pretraining epochs of resnet50, which is unquantative network of resnet50_quant
  82. 'data_load_mode': 'original' # the style of loading data into device, support 'original' or 'mindrecord'
  83. 'save_checkpoint':True # whether save checkpoint file after training finish
  84. 'save_checkpoint_epochs': 1 # the step from which start to save checkpoint file.
  85. 'keep_checkpoint_max': 50 # only keep the last keep_checkpoint_max checkpoint
  86. 'save_checkpoint_path': './' # the absolute full path to save the checkpoint file
  87. "warmup_epochs": 0 # number of warmup epochs
  88. 'lr_decay_mode': "cosine" # learning rate decay mode, including steps, steps_decay, cosine or liner
  89. 'use_label_smooth': True # whether use label smooth
  90. 'label_smooth_factor': 0.1 # label smooth factor
  91. 'lr_init': 0 # initial learning rate
  92. 'lr_max': 0.005 # the max learning rate
  93. ```
  94. ## [Training process](#contents)
  95. ### Usage
  96. - Ascend: sh run_train.sh Ascend [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH]\(optional)
  97. ### Launch
  98. ```
  99. # training example
  100. Ascend: bash run_train.sh Ascend ~/hccl.json ~/imagenet/train/ ~/pretrained_ckeckpoint
  101. ```
  102. ### Result
  103. 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 followings.
  104. ```
  105. epoch: 1 step: 5004, loss is 4.8995576
  106. epoch: 2 step: 5004, loss is 3.9235563
  107. epoch: 3 step: 5004, loss is 3.833077
  108. epoch: 4 step: 5004, loss is 3.2795618
  109. epoch: 5 step: 5004, loss is 3.1978393
  110. ```
  111. ## [Evaluation process](#contents)
  112. ### Usage
  113. You can start training using python or shell scripts. The usage of shell scripts as follows:
  114. - Ascend: sh run_infer.sh Ascend [DATASET_PATH] [CHECKPOINT_PATH]
  115. ### Launch
  116. ```
  117. # infer example
  118. shell:
  119. Ascend: sh run_infer.sh Ascend ~/imagenet/val/ ~/train/Resnet50-30_5004.ckpt
  120. ```
  121. > checkpoint can be produced in training process.
  122. ### Result
  123. Inference result will be stored in the example path, you can find result like the followings in `./eval/infer.log`.
  124. ```
  125. result: {'acc': 0.76576314102564111}
  126. ```
  127. # [Model description](#contents)
  128. ## [Performance](#contents)
  129. ### Evaluation Performance
  130. | Parameters | Ascend |
  131. | -------------------------- | ----------------------------------------------------------- |
  132. | Model Version | ResNet50 V1.5 |
  133. | Resource | Ascend 910, CPU 2.60GHz, 56cores, Memory 314G |
  134. | uploaded Date | 06/06/2020 (month/day/year) |
  135. | MindSpore Version | 0.3.0-alpha |
  136. | Dataset | ImageNet |
  137. | Training Parameters | epoch=30(with pretrained) or 120, steps per epoch=5004, batch_size=32 |
  138. | Optimizer | Momentum |
  139. | Loss Function | Softmax Cross Entropy |
  140. | outputs | probability |
  141. | Loss | 1.8 |
  142. | Speed | 8pcs: 407 ms/step |
  143. | Total time | 8pcs: 17 hours(30 epochs with pretrained) |
  144. | Parameters (M) | 25.5 |
  145. | Checkpoint for Fine tuning | 197M (.ckpt file) |
  146. | Scripts | [resnet50-quant script](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet50_quant) |
  147. ### Inference Performance
  148. | Parameters | Ascend |
  149. | ------------------- | --------------------------- |
  150. | Model Version | ResNet50 V1.5 |
  151. | Resource | Ascend 910, CPU 2.60GHz, 56cores, Memory 314G |
  152. | Uploaded Date | 06/06/2020 (month/day/year) |
  153. | MindSpore Version | 0.3.0-alpha |
  154. | Dataset | ImageNet |
  155. | batch_size | 32 |
  156. | outputs | probability |
  157. | Accuracy | ACC1[76.57%] ACC5[92.90%] |
  158. | Model for inference | 197M (.ckpt file) |
  159. # [Description of Random Situation](#contents)
  160. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
  161. # [ModelZoo Homepage](#contents)
  162. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).