Readme.md 12.7 KB
Newer Older
1 2 3 4 5 6
# Contents

- [MobileNetV2 Description](#mobilenetv2-description)
- [Model Architecture](#model-architecture)
- [Dataset](#dataset)
- [Features](#features)
P
Payne 已提交
7
  - [Mixed Precision](#mixed-precision)
8 9
- [Environment Requirements](#environment-requirements)
- [Script Description](#script-description)
P
Payne 已提交
10
  - [Script and Sample Code](#script-and-sample-code)
11 12
    - [Training Process](#training-process)
    - [Evaluation Process](#evaluation-process)
P
Payne 已提交
13
      - [Evaluation](#evaluation)
14
- [Model Description](#model-description)
P
Payne 已提交
15 16 17
  - [Performance](#performance)  
    - [Training Performance](#evaluation-performance)
    - [Inference Performance](#evaluation-performance)
18 19 20 21
- [Description of Random Situation](#description-of-random-situation)
- [ModelZoo Homepage](#modelzoo-homepage)

# [MobileNetV2 Description](#contents)
C
chenzomi 已提交
22 23 24 25 26

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.

[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.

27
# [Model architecture](#contents)
C
chenzomi 已提交
28 29 30 31 32

The overall network architecture of MobileNetV2 is show below:

[Link](https://arxiv.org/pdf/1905.02244)

33
# [Dataset](#contents)
C
chenzomi 已提交
34 35 36 37

Dataset used: [imagenet](http://www.image-net.org/)

- Dataset size: ~125G, 1.2W colorful images in 1000 classes
P
Payne 已提交
38 39
  - Train: 120G, 1.2W images
  - Test: 5G, 50000 images
C
chenzomi 已提交
40
- Data format: RGB images.
P
Payne 已提交
41
	- Note: Data will be processed in src/dataset.py
C
chenzomi 已提交
42

43
# [Features](#contents)
C
chenzomi 已提交
44

45
## [Mixed Precision(Ascend)](#contents)
C
chenzomi 已提交
46

P
Payne 已提交
47
The [mixed precision](https://www.mindspore.cn/tutorial/zh-CN/master/advanced_use/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.
48 49 50
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’.

# [Environment Requirements](#contents)
C
chenzomi 已提交
51

P
Payne 已提交
52 53
- Hardware(Ascend/GPU/CPU)
  - 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.
C
chenzomi 已提交
54 55 56
- Framework
  - [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- For more information, please check the resources below:
P
Payne 已提交
57
  - [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
C
chenzomi 已提交
58 59
  - [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

60
# [Script description](#contents)
C
chenzomi 已提交
61

62
## [Script and sample code](#contents)
C
chenzomi 已提交
63 64

```python
P
Payne 已提交
65 66 67 68 69 70 71 72
├── MobileNetV2
  ├── Readme.md     # descriptions about MobileNetV2
  ├── scripts
     ├──run_train.sh   # shell script for train, fine_tune or incremental  learn with CPU, GPU or Ascend
     ├──run_eval.sh    # shell script for evaluation with CPU, GPU or Ascend
  ├── src
     ├──args.py        # parse args
     ├──config.py      # parameter configuration
73 74
     ├──dataset.py     # creating dataset
     ├──launch.py      # start python script
P
Payne 已提交
75
     ├──lr_generator.py     # learning rate config
76
     ├──mobilenetV2.py      # MobileNetV2 architecture
P
Payne 已提交
77 78
     ├──models.py      # contain define_net and Loss, Monitor
     ├──utils.py       # utils to load ckpt_file for fine tune or incremental learn
79
  ├── train.py      # training script
P
Payne 已提交
80
  ├── eval.py       # evaluation script
C
chenzomi 已提交
81 82
```

83
## [Training process](#contents)
C
chenzomi 已提交
84 85 86

### Usage

87 88
You can start training using python or shell scripts. The usage of shell scripts as follows:

P
Payne 已提交
89 90 91
- Ascend: sh run_train.sh Ascend [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [RANK_TABLE_FILE] [DATASET_PATH] [TRAIN_METHOD] [CKPT_PATH]
- GPU: sh run_trian.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [TRAIN_METHOD] [CKPT_PATH]
- CPU: sh run_trian.sh CPU [DATASET_PATH] [TRAIN_METHOD] [CKPT_PATH]
C
chenzomi 已提交
92 93 94

### Launch

P
Payne 已提交
95
```
C
chenzomi 已提交
96
# training example
97
  python:
P
Payne 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111
      Ascend: python train.py --dataset_path ~/imagenet/train/ --platform Ascend --train_method train
      GPU: python train.py --dataset_path ~/imagenet/train/ --platform GPU --train_method train
      CPU: python train.py --dataset_path ~/imagenet/train/ --platform CPU --train_method train

  shell:
      Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json ~/imagenet/train/  train
      GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 ~/imagenet/train/ train
      CPU: sh run_train.sh CPU ~/imagenet/train/ train

# fine tune example
  python:
      Ascend: python train.py --dataset_path ~/imagenet/train/ --platform Ascend --train_method fine_tune ./pretrain_checkpoint/mobilenetv2_199.ckpt
      GPU: python train.py --dataset_path ~/imagenet/train/ --platform GPU --train_method fine_tune ./pretrain_checkpoint/mobilenetv2_199.ckpt
      CPU: python train.py --dataset_path ~/imagenet/train/ --platform CPU --train_method fine_tune ./pretrain_checkpoint/mobilenetv2_199.ckpt
112 113

  shell:
P
Payne 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127
      Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json ~/imagenet/train/  fine_tune ./pretrain_checkpoint/mobilenetv2_199.ckpt
      GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 ~/imagenet/train/ fine_tune ./pretrain_checkpoint/mobilenetv2_199.ckpt
      CPU: sh run_train.sh CPU ~/imagenet/train/ fine_tune ./pretrain_checkpoint/mobilenetv2_199.ckpt

# incremental learn example
  python:
      Ascend: python train.py --dataset_path ~/imagenet/train/ --platform Ascend --train_method incremental_learn ./pretrain_checkpoint/mobilenetv2_199.ckpt
      GPU: python train.py --dataset_path ~/imagenet/train/ --platform GPU --train_method incremental_learn ./pretrain_checkpoint/mobilenetv2_199.ckpt
      CPU: python train.py --dataset_path ~/imagenet/train/ --platform CPU --train_method incremental_learn ./pretrain_checkpoint/mobilenetv2_199.ckpt

  shell:
      Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json ~/imagenet/train/  incremental_learn ./pretrain_checkpoint/mobilenetv2_199.ckpt
      GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 ~/imagenet/train/ incremental_learn ./pretrain_checkpoint/mobilenetv2_199.ckpt
      CPU: sh run_train.sh CPU ~/imagenet/train/ incremental_learn ./pretrain_checkpoint/mobilenetv2_199.ckpt
C
chenzomi 已提交
128 129 130 131
```

### Result

P
Payne 已提交
132
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/train.log` like followings.
C
chenzomi 已提交
133

P
Payne 已提交
134
```
C
chenzomi 已提交
135 136 137 138 139 140
epoch: [  0/200], step:[  624/  625], loss:[5.258/5.258], time:[140412.236], lr:[0.100]
epoch time: 140522.500, per step time: 224.836, avg loss: 5.258
epoch: [  1/200], step:[  624/  625], loss:[3.917/3.917], time:[138221.250], lr:[0.200]
epoch time: 138331.250, per step time: 221.330, avg loss: 3.917
```

141
## [Eval process](#contents)
C
chenzomi 已提交
142 143 144

### Usage

145 146
You can start training using python or shell scripts. The usage of shell scripts as follows:

P
Payne 已提交
147 148 149
- Ascend: sh run_infer.sh Ascend [DATASET_PATH] [CHECKPOINT_PATH] [HEAD_CKPT_PATH]
- GPU: sh run_infer.sh GPU [DATASET_PATH] [CHECKPOINT_PATH] [HEAD_CKPT_PATH]
- CPU: sh run_infer.sh CPU [DATASET_PATH] [BACKBONE_CKPT_PATH] [HEAD_CKPT_PATH]
C
chenzomi 已提交
150 151 152

### Launch

P
Payne 已提交
153
```
C
chenzomi 已提交
154
# infer example
155
  python:
P
Payne 已提交
156 157 158
      Ascend: python eval.py --dataset_path ~/imagenet/val/ --pretrain_ckpt ~/train/mobilenet-200_625.ckpt --platform Ascend --head_ckpt ./checkpoint/mobilenetv2_199.ckpt
      GPU: python eval.py --dataset_path ~/imagenet/val/ --pretrain_ckpt ~/train/mobilenet-200_625.ckpt --platform GPU --head_ckpt ./checkpoint/mobilenetv2_199.ckpt
      CPU: python eval.py --dataset_path ~/imagenet/val/ --pretrain_ckpt ~/train/mobilenet-200_625.ckpt --platform CPU --head_ckpt ./checkpoint/mobilenetv2_199.ckpt
159 160

  shell:
P
Payne 已提交
161 162 163
      Ascend: sh run_infer.sh Ascend ~/imagenet/val/ ~/train/mobilenet-200_625.ckpt ./checkpoint/mobilenetv2_199.ckpt
      GPU: sh run_infer.sh GPU ~/imagenet/val/ ~/train/mobilenet-200_625.ckpt ./checkpoint/mobilenetv2_199.ckpt
      CPU: sh run_infer.sh GPU ~/imagenet/val/ ~/train/mobilenet-200_625.ckpt ./checkpoint/mobilenetv2_199.ckpt
C
chenzomi 已提交
164 165
```

P
Payne 已提交
166
> checkpoint can be produced in training process.
C
chenzomi 已提交
167 168 169

### Result

P
Payne 已提交
170
Inference result will be stored in the example path, you can find result like the followings in `val.log`.
C
chenzomi 已提交
171

P
Payne 已提交
172
```
C
chenzomi 已提交
173 174 175
result: {'acc': 0.71976314102564111} ckpt=/path/to/checkpoint/mobilenet-200_625.ckpt
```

176
# [Model description](#contents)
C
chenzomi 已提交
177

178
## [Performance](#contents)
C
chenzomi 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

### Training Performance

| Parameters                 | MobilenetV2                                                |                           |
| -------------------------- | ---------------------------------------------------------- | ------------------------- |
| Model Version              |                                                            | large                     |
| Resource                   | Ascend 910, cpu:2.60GHz 56cores, memory:314G               | NV SMX2 V100-32G          |
| uploaded Date              | 05/06/2020                                                 | 05/06/2020                |
| MindSpore Version          | 0.3.0                                                      | 0.3.0                     |
| Dataset                    | ImageNet                                                   | ImageNet                  |
| Training Parameters        | src/config.py                                              | src/config.py             |
| Optimizer                  | Momentum                                                   | Momentum                  |
| Loss Function              | SoftmaxCrossEntropy                                        | SoftmaxCrossEntropy       |
| outputs                    |                                                            |                           |
| Loss                       |                                                            | 1.913                     |
| Accuracy                   |                                                            | ACC1[77.09%] ACC5[92.57%] |
| Total time                 |                                                            |                           |
| Params (M)                 |                                                            |                           |
| Checkpoint for Fine tuning |                                                            |                           |
| Model for inference        |                                                            |                           |

#### Inference Performance

C
chenzomi 已提交
202
| Parameters                 |                               |                           |                      |
C
chenzomi 已提交
203 204
| -------------------------- | ----------------------------- | ------------------------- | -------------------- |
| Model Version              | V1                            |                           |                      |
W
wukesong 已提交
205
| Resource                   | Ascend 910                    | NV SMX2 V100-32G          | Ascend 310           |
C
chenzomi 已提交
206
| uploaded Date              | 05/06/2020                    | 05/22/2020                |                      |
P
Payne 已提交
207
| MindSpore Version          | 0.2.0                         | 0.2.0                     | 0.2.0                |
C
chenzomi 已提交
208 209 210 211 212 213 214 215
| Dataset                    | ImageNet, 1.2W                | ImageNet, 1.2W            | ImageNet, 1.2W       |
| batch_size                 |                               | 130(8P)                   |                      |
| outputs                    |                               |                           |                      |
| Accuracy                   |                               | ACC1[72.07%] ACC5[90.90%] |                      |
| Speed                      |                               |                           |                      |
| Total time                 |                               |                           |                      |
| Model for inference        |                               |                           |                      |

216 217 218 219 220
# [Description of Random Situation](#contents)

In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.

# [ModelZoo Homepage](#contents)
P
Payne 已提交
221 222

Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).