ModelZoo for Pytorch

November 30, 2020 · View on GitHub

This is a model zoo project under Pytorch. In this repo I will implement some of basic classification models which have good performance on ImageNet. Then I will train them in most fair way as possible and try my best to get SOTA model on ImageNet. In this repo I'll only consider FP16.

Usage

Environment

  • OS: Ubuntu 18.04
  • CUDA: 10.1, CuDNN: 7.6
  • Devices: I use 8 * RTX 2080ti(8 * V100 should be much better /cry). This project is in FP16 precision, it's recommend to use FP16 friendly devices like RTX series, V100. If you want to totally reproduce my research, you'd better use same batch size with me.

Requirement

  • Pytorch: >= 1.6.0 (Need torch.cuda.amp in version 1.6)
  • TorchToolbox: stable version. Helper functions to make your code simpler and more readable, it's a optional tools if you don't want to use it just write them yourself.

LMDB Dataset

  • No necessary.

If you found any IO bottleneck please use LMDB format dataset. A good way is try both and find out which is more faster.

I provide conversion script here.

Train script

python distribute_train_script --params

Here is a example

python distribute_train_script.py --data-path /s4/piston/ImageNet --batch-size 256 --dtype float16 \
                                  -j 48 --epochs 360 --lr 2.6 --warmup-epochs 5 --label-smoothing \
                                  --no-wd --wd 0.00003 --model GhostNet --log-interval 150 --model-info \
                                  --dist-url tcp://127.0.0.1:26548 --world-size 1 --rank 0

ToDo

  • Resume training
  • Try Nvidia-DALI
  • Multi-node(distributed) training by Apex or BytePS Pytorch
  • I may try AutoAugment.This project aims to train models by ourselves to observe and learn, it's impossible for me to train this, just copy feels meaningless.

Baseline models

modelepochsdtypebatch size*gpuslrtricksParams(M)/FLOPstop1/top5params/logs
resnet50120FP1612880.4-25.6/4.1G77.36/-Google Drive
resnet101120FP1612880.4-44.7/7.8G79.13/94.38Google Drive
resnet50v2120FP1612880.4-25.6/4.1G77.06/93.44Google Drive
resnet101v2120FP1612880.4-44.6/7.8G78.90/94.39Google Drive
ResNext50_32x4d120FP1612880.4-25.1/4.2G79.00/94.39
RegNetX4_0GF120FP1612880.4-22.2/4.0G78.40/94.04
RegNetY4_0GF120FP1612880.4-22.1/4.0G79.22/94.57
RegNetY6_4GF120FP1612880.4-31.2/6.4G79.69/94.82
ResNeST50120FP1612880.4-27.5/4.1G78.62/94.28
mobilenetv1150FP1625680.4-4.3/572.2M72.17/90.70Google Drive
mobilenetv2150FP1625680.4-3.5/305.3M71.94/90.59Google Drive
mobilenetv3 Large360FP1625682.6Label smoothing No decay bias Dropout5.5/219M75.64/92.61Google Drive
mobilenetv3 Small360FP1625682.6Label smoothing No decay bias Dropout3.0/57.8M67.83/87.78
GhostNet1.3360FP1640082.6Label smoothing No decay bias Dropout7.4/230.4M75.78/92.77Google Drive
  • I use nesterov SGD and cosine lr decay with 5 warmup epochs by default[2][3] (to save time), it's more common and effective.
  • *Batch size is pre GPU holds. Total batch size should be (batch size * gpus).

Optimized Models(with tricks)

  • In progress.

Ablation Study on Tricks

Here are lots of tricks to improve accuracy during this years.(If you have another idea please open an issue.) I want to verify them in a fair way.

Tricks: RandomRotation, OctConv[14], Drop out, Label Smoothing[4], Sync BN, SwitchNorm[6], Mixup[17], no decay bias[7], Cutout[5], Relu6[18], swish activation[10], Stochastic Depth[9], Lookahead Optimizer[11], Pre-active(ResnetV2)[12], DCNv2[13], LIP[16].

  • Delete line means make me out of memory.

Special: Zero-initialize the last BN, just call it 'Zero γ', only for post-active model.

I'll only use 120 epochs and 128*8 batch size to train them. I know some tricks may need train more time or larger batch size but it's not fair for others. You can think of it as a performance in the current situation.

modelepochsdtypebatch size*gpuslrtricksdegreetop1/top5improveparams/logs
resnet50120FP1612880.4--77.36/-baselineGoogle Drive
resnet50120FP1612880.4Label smoothingsmoothing=0.177.78/93.80+0.42Google Drive
resnet50120FP1612880.4No decay bias-77.28/93.61-0.08Google Drive
resnet50120FP1612880.4Sync BN-77.31/93.49-0.05Google Drive
resnet50120FP1612880.4Mixupalpha=0.277.49/93.73+0.13missing
resnet50120FP1612880.4RandomRotationdegree=1576.64/93.28-1.15Google Drive
resnet50120FP1612880.4Cutoutread code77.44/93.62+0.08Google Drive
resnet50120FP1612880.4Dropoutrate=0.377.11/93.58-0.25Google Drive
resnet50120FP1612880.4Lookahead-SGD-77.23/93.39-0.13Google Drive
resnet50v2120FP1612880.4pre-active-77.06/93.44-0.30Google Drive
oct_resnet50120FP1612880.4OctConvalpha=0.125--
resnet50120FP1612880.4Relu677.28/93.5-0.08Google Drive
resnet50120FP1612880.4-77.00/-DDP baseline
resnet50120FP1612880.4Gradient CentralizationConv only77.40/93.57+0.40
resnet50120FP1612880.4Zero γ77.24/-+0.24
resnet50120FP1612880.4No decay bias77.74/93.77+0.74
resnet50120FP1612880.4RandAugmentn=2,m=976.44/93.18-0.96
resnet50120FP1612880.4AutoAugment76.50/93.23-0.50
  • More epochs for Mixup, Cutout, Dropout may get better results.
  • Auto/Rand Augment may train 180 epochs better.

Citation

@misc{ModelZoo.pytorch,
  title = {Basic deep conv neural network reproduce and explore},
  author = {X.Yang},
  URL = {https://github.com/PistonY/ModelZoo.pytorch},
  year = {2019}
  }

Reference