Home

Awesome

image-classification-pytorch

This repo is designed for those who want to start their projects of image classification. It provides fast experiment setup and attempts to maximize the number of projects killed within the given time. It includes a few Convolutional Neural Network modules.You can build your own dnn easily.

Requirements

Python3 support only. Tested on CUDA9.0, cudnn7.

model

netinputsize
vggnet224
alexnet224
resnet224
inceptionV3299
inceptionV4299
squeezenet224
densenet224
dpnnet224
inception-resnet-v2299
mobilenetV2224
nasnet-a-large331
nasnet-mobile224
polynet331
resnext224
senet224
squeezenet224
pnasnet331
shufflenetV2224
mnasnet224
mobilenetV3224
oct-resnet224/256
......

pre-trained model

you can download pretrain model with url in ($net-module.py)

From torchvision package:

From Pretrained models for PyTorch package:

From mobilenetV2 package:

From shufflenetV2 package:

From MnasNet package:

From mobilenetV3 package:

From OctaveResnet package:

usage

configuration

configuredescription
model_module_nameeg: vgg_module
model_net_namenet function name in module, eg:vgg16
gpu_ideg: single GPU: "0", multi-GPUs:"0,1,3,4,7"
async_loadingmake an asynchronous copy to the GPU
is_tensorboardif use tensorboard for visualization
evaluate_before_trainevaluate accuracy before training
shuffleshuffle your training data
data_augaugment your training data
img_heightinput height
img_widthinput width
num_channelsinput channel
num_classesoutput number of classes
batch_sizetrain batch size
dataloader_workersnumber of workers when loading data
learning_ratelearning rate
learning_rate_decaylearning rate decat rate
learning_rate_decay_epochlearning rate decay per n-epoch
train_modeeg: "fromscratch","finetune","update"
file_label_separatorseparator between data-name and label. eg:"----"
pretrained_pathpretrain model path
pretrained_filepretrain model name. eg:"alexnet-owt-4df8aa71.pth"
pretrained_model_num_classesoutput number of classes when pretrain model trained. eg:1000 in imagenet
save_pathmodel path when saving
save_namemodel name when saving
train_data_root_dirtraining data root dir
val_data_root_dirtesting data root dir
train_data_filea txt filename which has training data and label list
val_data_filea txt filename which has testing data and label list

Training

1.make your training &. testing data and label list with txt file:

txt file with single label index eg:

apple.jpg----0
k.jpg----3
30.jpg----0
data/2.jpg----1
abc.jpg----1

2.configuration

3.train

python3 train.py

Inference

eg: trained by inception_resnet_v2, vgg/data/flowers/102:

python3 inference.py --image test.jpg --module inception_resnet_v2_module --net inception_resnet_v2 --model model.pth --size 299 --cls 102

tensorboardX

tensorboard --logdir='./logs/' runs

logdir is log dir in your project dir

References

1.https://github.com/pytorch
2.https://github.com/victoresque/pytorch-template
3.https://pytorch.org
5.https://github.com/yunjey/pytorch-tutorial
4.https://www.tensorflow.org
5.https://github.com/Cadene/pretrained-models.pytorch/tree/master/pretrainedmodels/models
6.https://github.com/ericsun99/MobileNet-V2-Pytorch
7.http://www.robots.ox.ac.uk/~vgg/data/flowers/102
8.https://github.com/ericsun99/Shufflenet-v2-Pytorch
9.https://github.com/billhhh/MnasNet-pytorch-pretrained
10.https://github.com/d-li14/octconv.pytorch
11.https://github.com/kuan-wang/pytorch-mobilenet-v3