Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
|
|
4 years ago | |
|---|---|---|
| .. | ||
| scripts | 5 years ago | |
| src | 4 years ago | |
| README.md | 4 years ago | |
| README_CN.md | 4 years ago | |
| eval.py | 5 years ago | |
| export.py | 4 years ago | |
| mindspore_hub_conf.py | 5 years ago | |
| train.py | 5 years ago | |
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.
The overall network architecture of MobileNetV2 is show below:
Dataset used: imagenet
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’.
├── 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
│ ├──dataset.py # creating dataset
│ ├──lr_generator.py # learning rate config
│ ├──mobilenetV2.py # MobileNetV2 architecture
│ ├──models.py # contain define_net and Loss, Monitor
│ ├──utils.py # utils to load ckpt_file for fine tune or incremental learn
├── train.py # training script
├── eval.py # evaluation script
├── export.py # export mindir script
├── mindspore_hub_conf.py # mindspore hub interface
You can start training using python or shell scripts. The usage of shell scripts as follows:
DATASET_PATH is the train dataset path. We use ImageFolderDataset as default dataset, which is a source dataset that reads images from a tree of directories. The directory structure is as follows, and you should use DATASET_PATH=dataset/train for training and DATASET_PATH=dataset/val for evaluation:
└─dataset
└─train
├─class1
├─0001.jpg
......
└─xxxx.jpg
......
├─classx
├─0001.jpg
......
└─xxxx.jpg
└─val
├─class1
├─0001.jpg
......
└─xxxx.jpg
......
├─classx
├─0001.jpg
......
└─xxxx.jpg
CKPT_PATH FREEZE_LAYER and FILTER_HEAD are optional, when set CKPT_PATH, FREEZE_LAYER must be set. FREEZE_LAYER should be in ["none", "backbone"], and if you set FREEZE_LAYER="backbone", the parameter in backbone will be freezed when training and the parameter in head will not be load from checkpoint. if FILTER_HEAD=True, the parameter in head will not be load from checkpoint.
RANK_TABLE_FILE is HCCL configuration file when running on Ascend.
The common restrictions on using the distributed service are as follows. For details, see the HCCL documentation.
- In a single-node system, a cluster of 1, 2, 4, or 8 devices is supported. In a multi-node system, a cluster of 8 x N devices is supported.
- Each host has four devices numbered 0 to 3 and four devices numbered 4 to 7 deployed on two different networks. During training of 2 or 4 devices, the devices must be connected and clusters cannot be created across networks.
# training example
python:
Ascend: python train.py --platform Ascend --dataset_path [TRAIN_DATASET_PATH]
GPU: python train.py --platform GPU --dataset_path [TRAIN_DATASET_PATH]
CPU: python train.py --platform CPU --dataset_path [TRAIN_DATASET_PATH]
shell:
Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json [TRAIN_DATASET_PATH]
GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 [TRAIN_DATASET_PATH]
CPU: sh run_train.sh CPU [TRAIN_DATASET_PATH]
# fine tune whole network example
python:
Ascend: python train.py --platform Ascend --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer none --filter_head True
GPU: python train.py --platform GPU --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer none --filter_head True
CPU: python train.py --platform CPU --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer none --filter_head True
shell:
Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json [TRAIN_DATASET_PATH] [CKPT_PATH] none True
GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 [TRAIN_DATASET_PATH] [CKPT_PATH] none True
CPU: sh run_train.sh CPU [TRAIN_DATASET_PATH] [CKPT_PATH] none True
# fine tune full connected layers example
python:
Ascend: python --platform Ascend train.py --dataset_path [TRAIN_DATASET_PATH]--pretrain_ckpt [CKPT_PATH] --freeze_layer backbone
GPU: python --platform GPU train.py --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer backbone
CPU: python --platform CPU train.py --dataset_path [TRAIN_DATASET_PATH] --pretrain_ckpt [CKPT_PATH] --freeze_layer backbone
shell:
Ascend: sh run_train.sh Ascend 8 0,1,2,3,4,5,6,7 hccl_config.json [TRAIN_DATASET_PATH] [CKPT_PATH] backbone
GPU: sh run_train.sh GPU 8 0,1,2,3,4,5,6,7 [TRAIN_DATASET_PATH] [CKPT_PATH] backbone
CPU: sh run_train.sh CPU [TRAIN_DATASET_PATH] [CKPT_PATH] backbone
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 .
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
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:
# eval example
python:
Ascend: python eval.py --platform Ascend --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt ./ckpt_0/mobilenetv2_15.ckpt
GPU: python eval.py --platform GPU --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt ./ckpt_0/mobilenetv2_15.ckpt
CPU: python eval.py --platform CPU --dataset_path [VAL_DATASET_PATH] --pretrain_ckpt ./ckpt_0/mobilenetv2_15.ckpt
shell:
Ascend: sh run_eval.sh Ascend [VAL_DATASET_PATH] ./checkpoint/mobilenetv2_head_15.ckpt
GPU: sh run_eval.sh GPU [VAL_DATASET_PATH] ./checkpoint/mobilenetv2_head_15.ckpt
CPU: sh run_eval.sh CPU [VAL_DATASET_PATH] ./checkpoint/mobilenetv2_head_15.ckpt
checkpoint can be produced in training process.
Inference result will be stored in the example path, you can find result like the followings in eval.log.
result: {'acc': 0.71976314102564111} ckpt=./ckpt_0/mobilenet-200_625.ckpt
python export.py --platform [PLATFORM] --ckpt_file [CKPT_PATH] --file_format [EXPORT_FORMAT]
EXPORT_FORMAT should be in ["AIR", "ONNX", "MINDIR"]
| Parameters | MobilenetV2 | |
|---|---|---|
| Model Version | V1 | V1 |
| Resource | Ascend 910; cpu 2.60GHz, 192cores; memory 755G; OS Euler2.8 | 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 | probability | probability |
| Loss | 1.908 | 1.913 |
| Accuracy | ACC1[71.78%] | ACC1[71.08%] |
| Total time | 753 min | 845 min |
| Params (M) | 3.3 M | 3.3 M |
| Checkpoint for Fine tuning | 27.3 M | 27.3 M |
| Scripts | Link |
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.
Please check the official homepage.
MindSpore is a new open source deep learning training/inference framework that could be used for mobile, edge and cloud scenarios.
C++ Python Text Unity3D Asset C other