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.7 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. # Mobilenet_V1
  2. - [Mobilenet_V1](#mobilenet_v1)
  3. - [MobileNetV1 Description](#mobilenetv1-description)
  4. - [Model architecture](#model-architecture)
  5. - [Dataset](#dataset)
  6. - [Features](#features)
  7. - [Mixed Precision(Ascend)](#mixed-precisionascend)
  8. - [Environment Requirements](#environment-requirements)
  9. - [Script description](#script-description)
  10. - [Script and sample code](#script-and-sample-code)
  11. - [Training process](#training-process)
  12. - [Usage](#usage)
  13. - [Launch](#launch)
  14. - [Result](#result)
  15. - [Evaluation process](#evaluation-process)
  16. - [Usage](#usage-1)
  17. - [Launch](#launch-1)
  18. - [Result](#result-1)
  19. - [Model description](#model-description)
  20. - [Performance](#performance)
  21. - [Training Performance](#training-performance)
  22. - [Description of Random Situation](#description-of-random-situation)
  23. - [ModelZoo Homepage](#modelzoo-homepage)
  24. ## [MobileNetV1 Description](#contents)
  25. MobileNetV1 is a efficient network for mobile and embedded vision applications. MobileNetV1 is based on a streamlined architecture that uses depth-wise separable convolutions to build light weight deep n.eural networks
  26. [Paper](https://arxiv.org/abs/1704.04861) Howard A G , Zhu M , Chen B , et al. MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications[J]. 2017.
  27. ## [Model architecture](#contents)
  28. The overall network architecture of MobileNetV1 is show below:
  29. [Link](https://arxiv.org/abs/1704.04861)
  30. ## [Dataset](#contents)
  31. Note that you can run the scripts based on the dataset mentioned in original paper or widely used in relevant domain/network architecture. In the following sections, we will introduce how to run the scripts using the related dataset below.
  32. Dataset used: [ImageNet2012](http://www.image-net.org/)
  33. - Dataset size 224*224 colorful images in 1000 classes
  34. - Train:1,281,167 images
  35. - Test: 50,000 images
  36. - Data format:jpeg
  37. - Note:Data will be processed in dataset.py
  38. - Download the dataset, the directory structure is as follows:
  39. ```bash
  40. └─dataset
  41. ├─ilsvrc # train dataset
  42. └─validation_preprocess # evaluate dataset
  43. ```
  44. ## Features
  45. ### Mixed Precision(Ascend)
  46. 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.
  47. 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’.
  48. ## Environment Requirements
  49. - Hardware(Ascend)
  50. - Prepare hardware environment with Ascend.
  51. - Framework
  52. - [MindSpore](https://www.mindspore.cn/install/en)
  53. - For more information, please check the resources below:
  54. - [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  55. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  56. ## Script description
  57. ### Script and sample code
  58. ```python
  59. ├── MobileNetV1
  60. ├── README.md # descriptions about MobileNetV1
  61. ├── scripts
  62. │ ├──run_distribute_train.sh # shell script for distribute train
  63. │ ├──run_standalone_train.sh # shell script for standalone train
  64. │ ├──run_eval.sh # shell script for evaluation
  65. ├── src
  66. │ ├──config.py # parameter configuration
  67. │ ├──dataset.py # creating dataset
  68. │ ├──lr_generator.py # learning rate config
  69. │ ├──mobilenet_v1_fpn.py # MobileNetV1 architecture
  70. │ ├──CrossEntropySmooth.py # loss function
  71. ├── train.py # training script
  72. ├── eval.py # evaluation script
  73. ```
  74. ## [Training process](#contents)
  75. ### Usage
  76. You can start training using python or shell scripts. The usage of shell scripts as follows:
  77. - Ascend: sh run_distribute_train.sh [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH] (optional)
  78. - CPU: sh run_train_CPU.sh [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH] (optional)
  79. For distributed training, a hccl configuration file with JSON format needs to be created in advance.
  80. Please follow the instructions in the link [hccn_tools](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools).
  81. ### Launch
  82. ```shell
  83. # training example
  84. python:
  85. Ascend: python train.py --device_target Ascend --dataset_path [TRAIN_DATASET_PATH]
  86. CPU: python train.py --device_target CPU --dataset_path [TRAIN_DATASET_PATH]
  87. shell:
  88. Ascend: sh run_distribute_train.sh [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  89. CPU: sh run_train_CPU.sh [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  90. ```
  91. ### Result
  92. Training result will be stored in the example path. Checkpoints will be stored at `ckpt_*` by default, and training log will be wrote to `./train_parallel*/log` with the platform Ascend .
  93. ```shell
  94. epoch: 89 step: 1251, loss is 2.1829057
  95. Epoch time: 146826.802, per step time: 117.368
  96. epoch: 90 step: 1251, loss is 2.3499017
  97. Epoch time: 150950.623, per step time: 120.664
  98. ```
  99. ## [Evaluation process](#contents)
  100. ### Usage
  101. 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:
  102. - Ascend: sh run_eval.sh [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  103. - CPU: sh run_eval_CPU.sh [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  104. ### Launch
  105. ```shell
  106. # eval example
  107. python:
  108. Ascend: python eval.py --dataset [cifar10|imagenet2012] --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt [CHECKPOINT_PATH]
  109. CPU: python eval.py --dataset [cifar10|imagenet2012] --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt [CHECKPOINT_PATH] --device_target CPU
  110. shell:
  111. Ascend: sh run_eval.sh [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  112. CPU: sh run_eval_CPU.sh [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
  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 `eval/log`.
  117. ```shell
  118. result: {'top_5_accuracy': 0.9010016025641026, 'top_1_accuracy': 0.7128004807692307} ckpt=./train_parallel0/ckpt_0/mobilenetv1-90_1251.ckpt
  119. ```
  120. ## Model description
  121. ### [Performance](#contents)
  122. #### Training Performance
  123. | Parameters | MobilenetV1 |
  124. | -------------------------- | ------------------------------------------------------------------------------------------- |
  125. | Model Version | V1 |
  126. | Resource | Ascend 910 * 4; cpu 2.60GHz, 192cores; memory 755G; OS Euler2.8 |
  127. | uploaded Date | 11/28/2020 |
  128. | MindSpore Version | 1.0.0 |
  129. | Dataset | ImageNet2012 |
  130. | Training Parameters | src/config.py |
  131. | Optimizer | Momentum |
  132. | Loss Function | SoftmaxCrossEntropy |
  133. | outputs | probability |
  134. | Loss | 2.3499017 |
  135. | Accuracy | ACC1[71.28%] |
  136. | Total time | 225 min |
  137. | Params (M) | 3.3 M |
  138. | Checkpoint for Fine tuning | 27.3 M |
  139. | Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/mobilenetv1) |
  140. ## [Description of Random Situation](#contents)
  141. <!-- In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py. -->
  142. 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.
  143. ## [ModelZoo Homepage](#contents)
  144. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).