Home

Awesome

<p align="center"><img width="40%" src="http://i.imgur.com/EMM7Qn2.pngg" /></p>

Image Classification Project Killer in PyTorch

This repo is designed for those who want to start their experiments two days before the deadline and kill the project in the last 6 hours. :new_moon_with_face: Inspired by fb.torch.resnet, it provides fast experiment setup and attempts to maximize the number of projects killed within the given time. Please feel free to submit issues or pull requests if you want to contribute.

News

Usage

Both Python 2.7 and 3 are supported; however, it was mainly tested on Python 3. Use python main.py -h to show all arguments.

Training

Train a ResNet-56 on CIFAR-10 with data augmentation using GPU0:

CUDA_VISIBLE_DEVICES=0 python main.py --data cifar10 --data_aug --arch resnet --depth 56 --save save/cifar10 -resnet-56 --epochs 164

Train a ResNet-110 on CIFAR-100 without data augmentation using GPU0 and GPU2:

CUDA_VISIBLE_DEVICES=0,2 python main.py --data cifar100 --arch resnet --depth 110 --save save/cifar100-resnet-110 --epochs 164

See scripts/cifar10.sh and scripts/cifar100.sh for more training examples.

Evaluation

python main.py --resume save/resnet-56/model_best.pth.tar --evaluate test --data cifar10

Adding your custom model

You can write your own model in a .py file and put it into models folder. All you need it to provide a createModel(arg1, arg2, **kwarg) function that returns the model which is an instance of nn.Module. Then you'll be able to use your model by setting --arch your_model_name (assuming that your model is in a the file models/your_model_name).

Show Training & Validation Results

Python script

getbest.py save/* FOLDER_1 FOLDER_2

In short, this script reads the scores.tsv in the saving folders and display the best validation errors of them.

Using Tensorboard

tensorboard --logdir save --port PORT

Features

Experiment Setup & Logging

Models (See models folder for details)

Datasets

CIFAR

Last 5000 samples in the original training set is used for validation. Each pixel is in [0, 1]. Based on experiments results, normalizing the data to zero mean and unit standard deviation seems to be redundant.

Results

Test Error Rate (in percentage) with validation set

The number of parameters are calculated based on CIFAR-10 model. ResNets were training with 164 epochs (the same as the default setting in fb.resnet.torch) and DenseNets were trained 300 epochs. Both are using batch_size=64.

ModelParametersCIFAR-10CIFAR-10 (aug)CIFAR-100CIFAR-100 (aug)
ResNet-560.86M6.82
ResNet-1101.73M
ResNet-110 with Stochastic Depth1.73M5.2524.2
DenseNet-BC-100 (k=12)0.8M5.34
DenseNet-BC-190 (k=40)25.6M
Your model

Top1 Testing Error Rate (in percentage)

Coming soon...

File Descriptions

Acknowledgement

This code is based on the ImageNet training script provided in PyTorch examples.

The author is not familiar with licensing. Please contact me there is there are any problems with it.