mindspore/model_zoo/official/cv/resnet50_quant
mindspore-ci-bot e6a4d932b4 !5350 [AutoParallel]Rectification distributed init
Merge pull request !5350 from lichen/rectification_init
2020-08-29 14:55:18 +08:00
..
models add manual quant network of resnet 2020-08-28 21:52:54 +08:00
scripts add mindspore hub for download ckpt file 2020-07-30 15:02:55 +08:00
src rectification init 2020-08-29 09:34:58 +08:00
Readme.md fix readme 2020-08-27 21:58:18 +08:00
eval.py add manual quant network of resnet 2020-08-28 21:52:54 +08:00
train.py !5444 Support manual convert to quantative network of resnet 2020-08-29 10:11:29 +08:00

Readme.md

Contents

resnet50 Description

ResNet-50 is a convolutional neural network that is 50 layers deep, which can classify ImageNet image nto 1000 object categories with 76% accuracy.

Paper Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun."Deep Residual Learning for Image Recognition." He, Kaiming , et al. "Deep Residual Learning for Image Recognition." IEEE Conference on Computer Vision & Pattern Recognition IEEE Computer Society, 2016.

This is the quantitative network of Resnet50.

Model architecture

The overall network architecture of Resnet50 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

├── resnet50_quant
  ├── Readme.md     # descriptions about Resnet50-Quant
  ├── scripts
     ├──run_train.sh   # shell script for train on Ascend
     ├──run_infer.sh    # shell script for evaluation on Ascend
  ├── model
     ├──resnet_quant.py      # define the network model of resnet50-quant
  ├── src
     ├──config.py      # parameter configuration
     ├──dataset.py     # creating dataset
     ├──launch.py      # start python script
     ├──lr_generator.py     # learning rate config
     ├──crossentropy.py     # define the crossentropy of resnet50-quant
  ├── train.py      # training script
  ├── eval.py       # evaluation script

Training process

Usage

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

  • Ascend: sh run_train.sh Ascend [DEVICE_NUM] [SERVER_IP(x.x.x.x)] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH][CKPT_PATH]

Launch

# training example
  shell:
      Ascend: sh run_train.sh Ascend 8 10.222.223.224 0,1,2,3,4,5,6,7 ~/resnet/train/ Resnet50-90_5004.ckpt

Result

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.

epoch: 1 step: 5004, loss is 4.8995576
epoch: 2 step: 5004, loss is 3.9235563
epoch: 3 step: 5004, loss is 3.833077
epoch: 4 step: 5004, loss is 3.2795618
epoch: 5 step: 5004, loss is 3.1978393

Eval process

Usage

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

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

Launch

# infer example
  shell:
      Ascend: sh run_infer.sh Ascend ~/imagenet/val/ ~/train/Resnet50-30_5004.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 ./eval/infer.log.

result: {'acc': 0.76576314102564111}

Model description

Performance

Training Performance

Parameters Resnet50
Model Version V1
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.8
Accuracy
Total time 16h
Params (M) batch_size=32, epoch=30
Checkpoint for Fine tuning
Model for inference

Evaluation Performance

Parameters Resnet50
Model Version V1
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[76.57%] ACC5[92.90%]
Speed 5ms/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.