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 11 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
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. # Contents
  2. - [ResNeXt50 Description](#resnext50-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. - [Model Export](#model-export)
  15. - [Model Description](#model-description)
  16. - [Performance](#performance)
  17. - [Training Performance](#evaluation-performance)
  18. - [Inference Performance](#evaluation-performance)
  19. - [Description of Random Situation](#description-of-random-situation)
  20. - [ModelZoo Homepage](#modelzoo-homepage)
  21. # [ResNeXt50 Description](#contents)
  22. ResNeXt is a simple, highly modularized network architecture for image classification. It designs results in a homogeneous, multi-branch architecture that has only a few hyper-parameters to set in ResNeXt. This strategy exposes a new dimension, which we call “cardinality” (the size of the set of transformations), as an essential factor in addition to the dimensions of depth and width.
  23. [Paper](https://arxiv.org/abs/1611.05431): Xie S, Girshick R, Dollár, Piotr, et al. Aggregated Residual Transformations for Deep Neural Networks. 2016.
  24. # [Model architecture](#contents)
  25. The overall network architecture of ResNeXt is show below:
  26. [Link](https://arxiv.org/abs/1611.05431)
  27. # [Dataset](#contents)
  28. Dataset used: [imagenet](http://www.image-net.org/)
  29. - Dataset size: ~125G, 1.2W colorful images in 1000 classes
  30. - Train: 120G, 1.2W images
  31. - Test: 5G, 50000 images
  32. - Data format: RGB images
  33. - Note: Data will be processed in src/dataset.py
  34. # [Features](#contents)
  35. ## [Mixed Precision](#contents)
  36. 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.
  37. 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’.
  38. # [Environment Requirements](#contents)
  39. - Hardware(Ascend/GPU)
  40. - Prepare hardware environment with Ascend or GPU processor.
  41. - Framework
  42. - [MindSpore](https://www.mindspore.cn/install/en)
  43. - For more information, please check the resources below:
  44. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  45. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  46. # [Script description](#contents)
  47. ## [Script and sample code](#contents)
  48. ```python
  49. .
  50. └─resnext50
  51. ├─README.md
  52. ├─scripts
  53. ├─run_standalone_train.sh # launch standalone training for ascend(1p)
  54. ├─run_distribute_train.sh # launch distributed training for ascend(8p)
  55. ├─run_standalone_train_for_gpu.sh # launch standalone training for gpu(1p)
  56. ├─run_distribute_train_for_gpu.sh # launch distributed training for gpu(8p)
  57. └─run_eval.sh # launch evaluating
  58. ├─src
  59. ├─backbone
  60. ├─_init_.py # initialize
  61. ├─resnet.py # resnext50 backbone
  62. ├─utils
  63. ├─_init_.py # initialize
  64. ├─cunstom_op.py # network operation
  65. ├─logging.py # print log
  66. ├─optimizers_init_.py # get parameters
  67. ├─sampler.py # distributed sampler
  68. ├─var_init_.py # calculate gain value
  69. ├─_init_.py # initialize
  70. ├─config.py # parameter configuration
  71. ├─crossentropy.py # CrossEntropy loss function
  72. ├─dataset.py # data preprocessing
  73. ├─head.py # common head
  74. ├─image_classification.py # get resnet
  75. ├─linear_warmup.py # linear warmup learning rate
  76. ├─warmup_cosine_annealing.py # learning rate each step
  77. ├─warmup_step_lr.py # warmup step learning rate
  78. ├─eval.py # eval net
  79. ├──train.py # train net
  80. ├──export.py # export mindir script
  81. ├──mindspore_hub_conf.py # mindspore hub interface
  82. ```
  83. ## [Script Parameters](#contents)
  84. Parameters for both training and evaluating can be set in config.py.
  85. ```config
  86. "image_height": '224,224' # image size
  87. "num_classes": 1000, # dataset class number
  88. "per_batch_size": 128, # batch size of input tensor
  89. "lr": 0.05, # base learning rate
  90. "lr_scheduler": 'cosine_annealing', # learning rate mode
  91. "lr_epochs": '30,60,90,120', # epoch of lr changing
  92. "lr_gamma": 0.1, # decrease lr by a factor of exponential lr_scheduler
  93. "eta_min": 0, # eta_min in cosine_annealing scheduler
  94. "T_max": 150, # T-max in cosine_annealing scheduler
  95. "max_epoch": 150, # max epoch num to train the model
  96. "warmup_epochs" : 1, # warmup epoch
  97. "weight_decay": 0.0001, # weight decay
  98. "momentum": 0.9, # momentum
  99. "is_dynamic_loss_scale": 0, # dynamic loss scale
  100. "loss_scale": 1024, # loss scale
  101. "label_smooth": 1, # label_smooth
  102. "label_smooth_factor": 0.1, # label_smooth_factor
  103. "ckpt_interval": 2000, # ckpt_interval
  104. "ckpt_path": 'outputs/', # checkpoint save location
  105. "is_save_on_master": 1,
  106. "rank": 0, # local rank of distributed
  107. "group_size": 1 # world size of distributed
  108. ```
  109. ## [Training Process](#contents)
  110. ### Usage
  111. You can start training by python script:
  112. ```script
  113. python train.py --data_dir ~/imagenet/train/ --platform Ascend --is_distributed 0
  114. ```
  115. or shell script:
  116. ```script
  117. Ascend:
  118. # distribute training example(8p)
  119. sh run_distribute_train.sh RANK_TABLE_FILE DATA_PATH
  120. # standalone training
  121. sh run_standalone_train.sh DEVICE_ID DATA_PATH
  122. GPU:
  123. # distribute training example(8p)
  124. sh run_distribute_train_for_gpu.sh DATA_PATH
  125. # standalone training
  126. sh run_standalone_train_for_gpu.sh DEVICE_ID DATA_PATH
  127. ```
  128. #### Launch
  129. ```bash
  130. # distributed training example(8p) for Ascend
  131. sh scripts/run_distribute_train.sh RANK_TABLE_FILE /dataset/train
  132. # standalone training example for Ascend
  133. sh scripts/run_standalone_train.sh 0 /dataset/train
  134. # distributed training example(8p) for GPU
  135. sh scripts/run_distribute_train_for_gpu.sh /dataset/train
  136. # standalone training example for GPU
  137. sh scripts/run_standalone_train_for_gpu.sh 0 /dataset/train
  138. ```
  139. You can find checkpoint file together with result in log.
  140. ## [Evaluation Process](#contents)
  141. ### Usage
  142. You can start training by python script:
  143. ```script
  144. python eval.py --data_dir ~/imagenet/val/ --platform Ascend --pretrained resnext.ckpt
  145. ```
  146. or shell script:
  147. ```script
  148. # Evaluation
  149. sh run_eval.sh DEVICE_ID DATA_PATH PRETRAINED_CKPT_PATH PLATFORM
  150. ```
  151. PLATFORM is Ascend or GPU, default is Ascend.
  152. #### Launch
  153. ```bash
  154. # Evaluation with checkpoint
  155. sh scripts/run_eval.sh 0 /opt/npu/datasets/classification/val /resnext50_100.ckpt Ascend
  156. ```
  157. #### Result
  158. Evaluation result will be stored in the scripts path. Under this, you can find result like the followings in log.
  159. ```log
  160. acc=78.16%(TOP1)
  161. acc=93.88%(TOP5)
  162. ```
  163. ## [Model Export](#contents)
  164. ```shell
  165. python export.py --device_target [PLATFORM] --ckpt_file [CKPT_PATH] --file_format [EXPORT_FORMAT]
  166. ```
  167. `EXPORT_FORMAT` should be in ["AIR", "ONNX", "MINDIR"]
  168. # [Model description](#contents)
  169. ## [Performance](#contents)
  170. ### Training Performance
  171. | Parameters | ResNeXt50 | |
  172. | -------------------------- | ---------------------------------------------------------- | ------------------------- |
  173. | Resource | Ascend 910, cpu:2.60GHz 192cores, memory:755G | NV SMX2 V100-32G |
  174. | uploaded Date | 06/30/2020 | 07/23/2020 |
  175. | MindSpore Version | 0.5.0 | 0.6.0 |
  176. | Dataset | ImageNet | ImageNet |
  177. | Training Parameters | src/config.py | src/config.py |
  178. | Optimizer | Momentum | Momentum |
  179. | Loss Function | SoftmaxCrossEntropy | SoftmaxCrossEntropy |
  180. | Loss | 1.76592 | 1.8965 |
  181. | Accuracy | 78%(TOP1) | 77.8%(TOP1) |
  182. | Total time | 7.8 h 8ps | 21.5 h 8ps |
  183. | Checkpoint for Fine tuning | 192 M(.ckpt file) | 192 M(.ckpt file) |
  184. #### Inference Performance
  185. | Parameters | | | |
  186. | -------------------------- | ----------------------------- | ------------------------- | -------------------- |
  187. | Resource | Ascend 910 | NV SMX2 V100-32G | Ascend 310 |
  188. | uploaded Date | 06/30/2020 | 07/23/2020 | 07/23/2020 |
  189. | MindSpore Version | 0.5.0 | 0.6.0 | 0.6.0 |
  190. | Dataset | ImageNet, 1.2W | ImageNet, 1.2W | ImageNet, 1.2W |
  191. | batch_size | 1 | 1 | 1 |
  192. | outputs | probability | probability | probability |
  193. | Accuracy | acc=78.16%(TOP1) | acc=78.05%(TOP1) | |
  194. # [Description of Random Situation](#contents)
  195. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
  196. # [ModelZoo Homepage](#contents)
  197. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).