Home

Awesome

Pytorch-cifar100

practice on cifar100 using pytorch

Requirements

This is my experiment eviroument

Usage

1. enter directory

$ cd pytorch-cifar100

2. dataset

I will use cifar100 dataset from torchvision since it's more convenient, but I also kept the sample code for writing your own dataset module in dataset folder, as an example for people don't know how to write it.

3. run tensorbard(optional)

Install tensorboard

$ pip install tensorboard
$ mkdir runs
Run tensorboard
$ tensorboard --logdir='runs' --port=6006 --host='localhost'

4. train the model

You need to specify the net you want to train using arg -net

# use gpu to train vgg16
$ python train.py -net vgg16 -gpu

sometimes, you might want to use warmup training by set -warm to 1 or 2, to prevent network diverge during early training phase.

The supported net args are:

squeezenet
mobilenet
mobilenetv2
shufflenet
shufflenetv2
vgg11
vgg13
vgg16
vgg19
densenet121
densenet161
densenet201
googlenet
inceptionv3
inceptionv4
inceptionresnetv2
xception
resnet18
resnet34
resnet50
resnet101
resnet152
preactresnet18
preactresnet34
preactresnet50
preactresnet101
preactresnet152
resnext50
resnext101
resnext152
attention56
attention92
seresnet18
seresnet34
seresnet50
seresnet101
seresnet152
nasnet
wideresnet
stochasticdepth18
stochasticdepth34
stochasticdepth50
stochasticdepth101

Normally, the weights file with the best accuracy would be written to the disk with name suffix 'best'(default in checkpoint folder).

5. test the model

Test the model using test.py

$ python test.py -net vgg16 -weights path_to_vgg16_weights_file

Implementated NetWork

Training Details

I didn't use any training tricks to improve accuray, if you want to learn more about training tricks, please refer to my another repo, contains various common training tricks and their pytorch implementations.

I follow the hyperparameter settings in paper Improved Regularization of Convolutional Neural Networks with Cutout, which is init lr = 0.1 divide by 5 at 60th, 120th, 160th epochs, train for 200 epochs with batchsize 128 and weight decay 5e-4, Nesterov momentum of 0.9. You could also use the hyperparameters from paper Regularizing Neural Networks by Penalizing Confident Output Distributions and Random Erasing Data Augmentation, which is initial lr = 0.1, lr divied by 10 at 150th and 225th epochs, and training for 300 epochs with batchsize 128, this is more commonly used. You could decrese the batchsize to 64 or whatever suits you, if you dont have enough gpu memory.

You can choose whether to use TensorBoard to visualize your training procedure

Results

The result I can get from a certain model, since I use the same hyperparameters to train all the networks, some networks might not get the best result from these hyperparameters, you could try yourself by finetuning the hyperparameters to get better result.

datasetnetworkparamstop1 errtop5 errepoch(lr = 0.1)epoch(lr = 0.02)epoch(lr = 0.004)epoch(lr = 0.0008)total epoch
cifar100mobilenet3.3M34.0210.5660604040200
cifar100mobilenetv22.36M31.9209.0260604040200
cifar100squeezenet0.78M30.598.3660604040200
cifar100shufflenet1.0M29.948.3560604040200
cifar100shufflenetv21.3M30.498.4960604040200
cifar100vgg11_bn28.5M31.3611.8560604040200
cifar100vgg13_bn28.7M28.009.7160604040200
cifar100vgg16_bn34.0M27.078.8460604040200
cifar100vgg19_bn39.0M27.778.8460604040200
cifar100resnet1811.2M24.396.9560604040200
cifar100resnet3421.3M23.246.6360604040200
cifar100resnet5023.7M22.616.0460604040200
cifar100resnet10142.7M22.225.6160604040200
cifar100resnet15258.3M22.315.8160604040200
cifar100preactresnet1811.3M27.088.5360604040200
cifar100preactresnet3421.5M24.797.6860604040200
cifar100preactresnet5023.9M25.738.1560604040200
cifar100preactresnet10142.9M24.847.8360604040200
cifar100preactresnet15258.6M22.716.6260604040200
cifar100resnext5014.8M22.236.0060604040200
cifar100resnext10125.3M22.225.9960604040200
cifar100resnext15233.3M22.405.5860604040200
cifar100attention5955.7M33.7512.9060604040200
cifar100attention92102.5M36.5211.4760604040200
cifar100densenet1217.0M22.996.4560604040200
cifar100densenet16126M21.566.0460606040200
cifar100densenet20118M21.465.960604040200
cifar100googlenet6.2M21.975.9460604040200
cifar100inceptionv322.3M22.816.3960604040200
cifar100inceptionv441.3M24.146.9060604040200
cifar100inceptionresnetv265.4M27.519.1160604040200
cifar100xception21.0M25.077.3260604040200
cifar100seresnet1811.4M23.566.6860604040200
cifar100seresnet3421.6M22.076.1260604040200
cifar100seresnet5026.5M21.425.5860604040200
cifar100seresnet10147.7M20.985.4160604040200
cifar100seresnet15266.2M20.665.1960604040200
cifar100nasnet5.2M22.715.9160604040200
cifar100wideresnet-40-1055.9M21.255.7760604040200
cifar100stochasticdepth1811.22M31.408.8460604040200
cifar100stochasticdepth3421.36M27.727.3260604040200
cifar100stochasticdepth5023.71M23.355.7660604040200
cifar100stochasticdepth10142.69M21.285.3960604040200