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.9 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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # Contents
  2. - [MobileNetV2 Description](#mobilenetv2-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. - [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. This is the quantitative network of MobileNetV2.
  23. # [Model architecture](#contents)
  24. The overall network architecture of MobileNetV2 is show below:
  25. [Link](https://arxiv.org/pdf/1905.02244)
  26. # [Dataset](#contents)
  27. Dataset used: [imagenet](http://www.image-net.org/)
  28. - Dataset size: ~125G, 1.2W colorful images in 1000 classes
  29. - Train: 120G, 1.2W images
  30. - Test: 5G, 50000 images
  31. - Data format: RGB images.
  32. - Note: Data will be processed in src/dataset.py
  33. # [Features](#contents)
  34. ## [Mixed Precision](#contents)
  35. 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.
  36. 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’.
  37. # [Environment Requirements](#contents)
  38. - Hardware:Ascend
  39. - 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.
  40. - Framework
  41. - [MindSpore](https://www.mindspore.cn/install/en)
  42. - For more information, please check the resources below
  43. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  44. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  45. # [Script description](#contents)
  46. ## [Script and sample code](#contents)
  47. ```python
  48. ├── mobileNetv2_quant
  49. ├── Readme.md # descriptions about MobileNetV2-Quant
  50. ├── scripts
  51. │ ├──run_train.sh # shell script for train on Ascend
  52. │ ├──run_infer.sh # shell script for evaluation on Ascend
  53. ├── src
  54. │ ├──config.py # parameter configuration
  55. │ ├──dataset.py # creating dataset
  56. │ ├──launch.py # start python script
  57. │ ├──lr_generator.py # learning rate config
  58. │ ├──mobilenetV2.py # MobileNetV2 architecture
  59. │ ├──utils.py # supply the monitor module
  60. ├── train.py # training script
  61. ├── eval.py # evaluation script
  62. ├── export.py # export checkpoint files into air/onnx
  63. ```
  64. ## [Script Parameters](#contents)
  65. Parameters for both training and evaluation can be set in config.py
  66. - config for MobileNetV2-quant, ImageNet2012 dataset
  67. ```python
  68. 'num_classes': 1000 # the number of classes in the dataset
  69. 'batch_size': 134 # training batch size
  70. 'epoch_size': 60 # training epochs of mobilenetv2-quant
  71. 'start_epoch':200 # pretraining epochs of unquantative network
  72. 'warmup_epochs': 0 # number of warmup epochs
  73. 'lr': 0.3 #learning rate
  74. 'momentum': 0.9 # momentum
  75. 'weight_decay': 4e-5 # weight decay value
  76. 'loss_scale': 1024 # the initial loss_scale value
  77. 'label_smooth': 0.1 #label smooth factor
  78. 'loss_scale': 1024 # the initial loss_scale value
  79. 'save_checkpoint':True # whether save checkpoint file after training finish
  80. 'save_checkpoint_epochs': 1 # the step from which start to save checkpoint file.
  81. 'keep_checkpoint_max': 300 # only keep the last keep_checkpoint_max checkpoint
  82. 'save_checkpoint_path': './checkpoint' # the absolute full path to save the checkpoint file
  83. ```
  84. ## [Training process](#contents)
  85. ### Usage
  86. You can start training using python or shell scripts. The usage of shell scripts as follows:
  87. - bash run_train.sh [Ascend] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH]\(optional)
  88. - bash run_train.sh [GPU] [DEVICE_ID_LIST] [DATASET_PATH] [PRETRAINED_CKPT_PATH]\(optional)
  89. ### Launch
  90. ``` bash
  91. # training example
  92. >>> bash run_train.sh Ascend ~/hccl_4p_0123_x.x.x.x.json ~/imagenet/train/ ~/mobilenet.ckpt
  93. >>> bash run_train.sh GPU 1,2 ~/imagenet/train/ ~/mobilenet.ckpt
  94. ```
  95. ### Result
  96. Training result will be stored in the example path. Checkpoints trained by `Ascend` will be stored at `./train/device$i/checkpoint` by default, and training log will be redirected to `./train/device$i/train.log`. Checkpoints trained by `GPU` will be stored in `./train/checkpointckpt_$i` by default, and training log will be redirected to `./train/train.log`.
  97. `train.log` is as follows:
  98. ```
  99. epoch: [ 0/200], step:[ 624/ 625], loss:[5.258/5.258], time:[140412.236], lr:[0.100]
  100. epoch time: 140522.500, per step time: 224.836, avg loss: 5.258
  101. epoch: [ 1/200], step:[ 624/ 625], loss:[3.917/3.917], time:[138221.250], lr:[0.200]
  102. epoch time: 138331.250, per step time: 221.330, avg loss: 3.917
  103. ```
  104. ## [Evaluation process](#contents)
  105. ### Usage
  106. You can start training using python or shell scripts. The usage of shell scripts as follows:
  107. - Ascend: sh run_infer_quant.sh Ascend [DATASET_PATH] [CHECKPOINT_PATH]
  108. ### Launch
  109. ```
  110. # infer example
  111. shell:
  112. Ascend: sh run_infer_quant.sh Ascend ~/imagenet/val/ ~/train/mobilenet-60_1601.ckpt
  113. ```
  114. > checkpoint can be produced in training process.
  115. ### Result
  116. Inference result will be stored in the example path, you can find result like the followings in `./val/infer.log`.
  117. ```
  118. result: {'acc': 0.71976314102564111}
  119. ```
  120. # [Model description](#contents)
  121. ## [Performance](#contents)
  122. ### Training Performance
  123. | Parameters | MobilenetV2 |
  124. | -------------------------- | ---------------------------------------------------------- |
  125. | Model Version | V2 |
  126. | Resource | Ascend 910, cpu:2.60GHz 192cores, memory:755G |
  127. | uploaded Date | 06/06/2020 |
  128. | MindSpore Version | 0.3.0 |
  129. | Dataset | ImageNet |
  130. | Training Parameters | src/config.py |
  131. | Optimizer | Momentum |
  132. | Loss Function | SoftmaxCrossEntropy |
  133. | outputs | ckpt file |
  134. | Loss | 1.913 |
  135. | Accuracy | |
  136. | Total time | 16h |
  137. | Params (M) | batch_size=192, epoch=60 |
  138. | Checkpoint for Fine tuning | |
  139. | Model for inference | |
  140. #### Evaluation Performance
  141. | Parameters | |
  142. | -------------------------- | ----------------------------- |
  143. | Model Version | V2 |
  144. | Resource | Ascend 910 |
  145. | uploaded Date | 06/06/2020 |
  146. | MindSpore Version | 0.3.0 |
  147. | Dataset | ImageNet, 1.2W |
  148. | batch_size | 130(8P) |
  149. | outputs | probability |
  150. | Accuracy | ACC1[71.78%] ACC5[90.90%] |
  151. | Speed | 200ms/step |
  152. | Total time | 5min |
  153. | Model for inference | |
  154. # [Description of Random Situation](#contents)
  155. In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
  156. # [ModelZoo Homepage](#contents)
  157. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).