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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. # Contents
  2. - [MobileNetV2 Description](#mobilenetv2-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Features](#features)
  6. - [Mixed Precision](#mixed-precision(ascend))
  7. - [Environment Requirements](#environment-requirements)
  8. - [Script Description](#script-description)
  9. - [Script and Sample Code](#script-and-sample-code)
  10. - [Training Process](#training-process)
  11. - [Evaluation Process](#eval-process)
  12. - [Export MindIR](#export-mindir)
  13. - [Model Description](#model-description)
  14. - [Performance](#performance)
  15. - [Training Performance](#training-performance)
  16. - [Evaluation Performance](#evaluation-performance)
  17. - [Description of Random Situation](#description-of-random-situation)
  18. - [ModelZoo Homepage](#modelzoo-homepage)
  19. # [MobileNetV2 Description](#contents)
  20. MobileNetV2 is tuned to mobile phone CPUs through a combination of hardware- aware network architecture search (NAS) complemented by the NetAdapt algorithm and then subsequently improved through novel architecture advances.Nov 20, 2019.
  21. [Paper](https://arxiv.org/pdf/1905.02244) Howard, Andrew, Mark Sandler, Grace Chu, Liang-Chieh Chen, Bo Chen, Mingxing Tan, Weijun Wang et al. "Searching for MobileNetV2." In Proceedings of the IEEE International Conference on Computer Vision, pp. 1314-1324. 2019.
  22. # [Model architecture](#contents)
  23. The overall network architecture of MobileNetV2 is show below:
  24. [Link](https://arxiv.org/pdf/1905.02244)
  25. # [Dataset](#contents)
  26. Dataset used: [imagenet](http://www.image-net.org/)
  27. - Dataset size: ~125G, 1.2W colorful images in 1000 classes
  28. - Train: 120G, 1.2W images
  29. - Test: 5G, 50000 images
  30. - Data format: RGB images.
  31. - Note: Data will be processed in src/dataset.py
  32. # [Features](#contents)
  33. ## [Mixed Precision(Ascend)](#contents)
  34. 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.
  35. 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’.
  36. # [Environment Requirements](#contents)
  37. - Hardware(Ascend/GPU/CPU)
  38. - Prepare hardware environment with Ascend、GPU or CPU processor. 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.
  39. - Framework
  40. - [MindSpore](https://www.mindspore.cn/install/en)
  41. - For more information, please check the resources below:
  42. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  43. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  44. # [Script description](#contents)
  45. ## [Script and sample code](#contents)
  46. ```python
  47. ├── MobileNetV2
  48. ├── README.md # descriptions about MobileNetV2
  49. ├── scripts
  50. │ ├──run_train.sh # shell script for train, fine_tune or incremental learn with CPU, GPU or Ascend
  51. │ ├──run_eval.sh # shell script for evaluation with CPU, GPU or Ascend
  52. ├── src
  53. │ ├──args.py # parse args
  54. │ ├──config.py # parameter configuration
  55. │ ├──dataset.py # creating dataset
  56. │ ├──lr_generator.py # learning rate config
  57. │ ├──mobilenetV2.py # MobileNetV2 architecture
  58. │ ├──models.py # contain define_net and Loss, Monitor
  59. │ ├──utils.py # utils to load ckpt_file for fine tune or incremental learn
  60. ├── train.py # training script
  61. ├── eval.py # evaluation script
  62. ├── export.py # export mindir script
  63. ├── mindspore_hub_conf.py # mindspore hub interface
  64. ```
  65. ## [Training process](#contents)
  66. ### Usage
  67. You can start training using python or shell scripts. The usage of shell scripts as follows:
  68. - Ascend: sh run_train.sh Ascend [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [RANK_TABLE_FILE] [DATASET_PATH] [CKPT_PATH] [FREEZE_LAYER]
  69. - GPU: sh run_trian.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH] [FREEZE_LAYER]
  70. - CPU: sh run_trian.sh CPU [DATASET_PATH] [CKPT_PATH] [FREEZE_LAYER]
  71. ### Launch
  72. ```shell
  73. # training example
  74. python:
  75. Ascend: python train.py --platform Ascend --dataset_path [TRAIN_DATASET_PATH]
  76. GPU: python train.py --platform GPU --dataset_path [TRAIN_DATASET_PATH]
  77. CPU: python train.py --platform CPU --dataset_path [TRAIN_DATASET_PATH]
  78. shell:
  79. Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json [TRAIN_DATASET_PATH]
  80. GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 [TRAIN_DATASET_PATH]
  81. CPU: sh run_train.sh CPU [TRAIN_DATASET_PATH]
  82. # fine tune whole network example
  83. python:
  84. Ascend: python train.py --platform Ascend --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer none
  85. GPU: python train.py --platform GPU --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer none
  86. CPU: python train.py --platform CPU --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer none
  87. shell:
  88. Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json [TRAIN_DATASET_PATH] [CKPT_PATH] none
  89. GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 [TRAIN_DATASET_PATH] [CKPT_PATH] none
  90. CPU: sh run_train.sh CPU [TRAIN_DATASET_PATH] [CKPT_PATH] none
  91. # fine tune full connected layers example
  92. python:
  93. Ascend: python --platform Ascend train.py --dataset_path [TRAIN_DATASET_PATH]--pretrain_ckpt [CKPT_PATH] --freeze_layer backbone
  94. GPU: python --platform GPU train.py --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer backbone
  95. CPU: python --platform CPU train.py --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer backbone
  96. shell:
  97. Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json [TRAIN_DATASET_PATH] [CKPT_PATH] backbone
  98. GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 [TRAIN_DATASET_PATH] [CKPT_PATH] backbone
  99. CPU: sh run_train.sh CPU [TRAIN_DATASET_PATH] [CKPT_PATH] backbone
  100. ```
  101. ### Result
  102. Training result will be stored in the example path. Checkpoints will be stored at `. /checkpoint` by default, and training log will be redirected to `./train.log` like followings with the platform CPU and GPU, will be wrote to `./train/rank*/log*.log` with the platform Ascend .
  103. ```shell
  104. epoch: [ 0/200], step:[ 624/ 625], loss:[5.258/5.258], time:[140412.236], lr:[0.100]
  105. epoch time: 140522.500, per step time: 224.836, avg loss: 5.258
  106. epoch: [ 1/200], step:[ 624/ 625], loss:[3.917/3.917], time:[138221.250], lr:[0.200]
  107. epoch time: 138331.250, per step time: 221.330, avg loss: 3.917
  108. ```
  109. ## [Evaluation process](#contents)
  110. ### Usage
  111. You can start training using python or shell scripts.If the train method is train or fine tune, should not input the `[CHECKPOINT_PATH]` The usage of shell scripts as follows:
  112. - Ascend: sh run_eval.sh Ascend [DATASET_PATH] [CHECKPOINT_PATH]
  113. - GPU: sh run_eval.sh GPU [DATASET_PATH] [CHECKPOINT_PATH]
  114. - CPU: sh run_eval.sh CPU [DATASET_PATH] [BACKBONE_CKPT_PATH]
  115. ### Launch
  116. ```shell
  117. # eval example
  118. python:
  119. Ascend: python eval.py --platform Ascend --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt ./ckpt_0/mobilenetv2_15.ckpt
  120. GPU: python eval.py --platform GPU --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt ./ckpt_0/mobilenetv2_15.ckpt
  121. CPU: python eval.py --platform CPU --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt ./ckpt_0/mobilenetv2_15.ckpt
  122. shell:
  123. Ascend: sh run_eval.sh Ascend [VAL_DATASET_PATH] ./checkpoint/mobilenetv2_head_15.ckpt
  124. GPU: sh run_eval.sh GPU [VAL_DATASET_PATH] ./checkpoint/mobilenetv2_head_15.ckpt
  125. CPU: sh run_eval.sh CPU [VAL_DATASET_PATH] ./checkpoint/mobilenetv2_head_15.ckpt
  126. ```
  127. > checkpoint can be produced in training process.
  128. ### Result
  129. Inference result will be stored in the example path, you can find result like the followings in `eval.log`.
  130. ```shell
  131. result: {'acc': 0.71976314102564111} ckpt=./ckpt_0/mobilenet-200_625.ckpt
  132. ```
  133. ## [Export MindIR](#contents)
  134. Change the export mode and export file in `src/config.py`, and run `export.py`.
  135. ```
  136. python export.py --platform [PLATFORM] --pretrain_ckpt [CKPT_PATH]
  137. ```
  138. # [Model description](#contents)
  139. ## [Performance](#contents)
  140. ### Training Performance
  141. | Parameters | MobilenetV2 | |
  142. | -------------------------- | ---------------------------------------------------------- | ------------------------- |
  143. | Model Version | V1 | V1 |
  144. | Resource | Ascend 910, cpu:2.60GHz 192cores, memory:755G | NV SMX2 V100-32G |
  145. | uploaded Date | 05/06/2020 | 05/06/2020 |
  146. | MindSpore Version | 0.3.0 | 0.3.0 |
  147. | Dataset | ImageNet | ImageNet |
  148. | Training Parameters | src/config.py | src/config.py |
  149. | Optimizer | Momentum | Momentum |
  150. | Loss Function | SoftmaxCrossEntropy | SoftmaxCrossEntropy |
  151. | outputs | probability | probability |
  152. | Loss | 1.908 | 1.913 |
  153. | Accuracy | ACC1[71.78%] | ACC1[71.08%] |
  154. | Total time | 753 min | 845 min |
  155. | Params (M) | 3.3 M | 3.3 M |
  156. | Checkpoint for Fine tuning | 27.3 M | 27.3 M |
  157. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/mobilenetv2)|
  158. # [Description of Random Situation](#contents)
  159. <!-- In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py. -->
  160. In train.py, we set the seed which is used by numpy.random, mindspore.common.Initializer, mindspore.ops.composite.random_ops and mindspore.nn.probability.distribution.
  161. # [ModelZoo Homepage](#contents)
  162. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).