You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mindspore/model_zoo/official/cv/mobilenetv2_quant
mindspore-ci-bot 5f34c71ad5
!5700 rename mirror_mean to gradient_mean
5 years ago
..
scripts add training scripts and modify readme of mobilenetv2_quant and 5 years ago
src fix readme 5 years ago
Readme.md add training scripts and modify readme of mobilenetv2_quant and 5 years ago
eval.py !5502 Mod SoftmaxCrossEntropyWithlogits 5 years ago
export.py Change export interface 5 years ago
train.py rename mirror_mean to gradients_mean 5 years ago

Readme.md

Contents

MobileNetV2 Description

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

This is the quantitative network of MobileNetV2.

Model architecture

The overall network architecture of MobileNetV2 is show below:

Link

Dataset

Dataset used: imagenet

  • Dataset size: ~125G, 1.2W colorful images in 1000 classes
    • Train: 120G, 1.2W images
    • Test: 5G, 50000 images
  • Data format: RGB images.
    • Note: Data will be processed in src/dataset.py

Features

Mixed Precision(Ascend)

The mixed precision 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. 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

Script description

Script and sample code

├── mobileNetv2_quant
  ├── Readme.md     # descriptions about MobileNetV2-Quant
  ├── scripts
     ├──run_train.sh   # shell script for train on Ascend and GPU
     ├──run_infer_quant.sh    # shell script for evaluation on Ascend
  ├── src
     ├──config.py      # parameter configuration
     ├──dataset.py     # creating dataset
     ├──launch.py      # start python script
     ├──lr_generator.py     # learning rate config
     ├──mobilenetV2.py      # MobileNetV2 architecture
     ├──utils.py       # supply the monitor module
  ├── train.py      # training script
  ├── eval.py       # evaluation script
  ├── export.py     # export checkpoint files into air/onnx

Training process

Usage

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

  • bash run_train.sh [Ascend] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
  • bash run_train.sh [GPU] [DEVICE_ID_LIST] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)

Launch

  # training example
  >>> bash run_train.sh Ascend ~/hccl_4p_0123_x.x.x.x.json ~/imagenet/train/ ~/mobilenet.ckpt
  >>> bash run_train.sh GPU 1,2 ~/imagenet/train/ ~/mobilenet.ckpt

Result

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.
train.log is as follows:

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

Eval process

Usage

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

  • Ascend: sh run_infer_quant.sh Ascend [DATASET_PATH] [CHECKPOINT_PATH]

Launch

# infer example
  shell:
      Ascend: sh run_infer_quant.sh Ascend ~/imagenet/val/ ~/train/mobilenet-60_1601.ckpt

checkpoint can be produced in training process.

Result

Inference result will be stored in the example path, you can find result like the followings in ./val/infer.log.

result: {'acc': 0.71976314102564111}

Model description

Performance

Training Performance

Parameters MobilenetV2
Model Version V2
Resource Ascend 910, cpu:2.60GHz 56cores, memory:314G
uploaded Date 06/06/2020
MindSpore Version 0.3.0
Dataset ImageNet
Training Parameters src/config.py
Optimizer Momentum
Loss Function SoftmaxCrossEntropy
outputs ckpt file
Loss 1.913
Accuracy
Total time 16h
Params (M) batch_size=192, epoch=60
Checkpoint for Fine tuning
Model for inference

Evaluation Performance

Parameters
Model Version V2
Resource Ascend 910
uploaded Date 06/06/2020
MindSpore Version 0.3.0
Dataset ImageNet, 1.2W
batch_size 130(8P)
outputs probability
Accuracy ACC1[71.78%] ACC5[90.90%]
Speed 200ms/step
Total time 5min
Model for inference

Description of Random Situation

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

ModelZoo Homepage

Please check the official homepage.