This repository contains comparisons of different convolution neural networks for the CIFAR-10 data-set.ImageNet pretrained models have been fine tuned on CIFAR-10 dataset.The script automatically downloads the cifar 10 dataset. Clone this repo please follow the following steps
git clone https://github.com/L-A-Sandhu/Efficient-Image-Classification.git
The rest of the repository is divided as follows.
- Requirements
- Fine Tuning
- Using Pretrained Model
- Summary
This repository requires
- tensorflow
- matplotlib
- scipy
- protobuf
For complete installation please follow the following steps
cd M0bile_Net/
conda create -n <environment -name> python==3.7.4
conda activate <environment-name>
pip install -r requirements.txt
cd ../
This section disccusses the fine tunning method for Mobile Net and Inception net. The keras implementations of Mobile Net and Inception Net is used in this work. Their weights are trained on Image Net dataset. However, this work fine tuned the model on cifar10 dataset. please follow the following set of commands
cd < M0bile_Net or Inception_NET>
python <Mobile-Net.py or Inception-Net.py > --model_dir=<Location for saving model> --inp=<tune, train, test, resume > --b_s=< Batch size> --e=<epoch>
example command
python Mobile-Net.py --model_dir='./checkpoint/' --inp=tune --b_s=16 --e=100
python <Mobile-Net.py or Inception-Net.py > --model_dir=<Location for saving model> --inp=<tune, train, test, resume > --b_s=< Batch size> --e=<epoch>
example command
python Mobile-Net.py --model_dir='./checkpoint/' --inp=train --b_s=16 --e=100
python <Mobile-Net.py or Inception-Net.py > --model_dir=<Location for saving model> --inp=<tune, test, train, resume>
example command
python Mobile-Net.py --model_dir='./checkpoint/' --inp=test
python <Mobile-Net.py or Inception-Net.py > --model_dir=<Location for saving/loading model> --inp= <tune, train, test, resume,conv > --b_s=< Batch size> --e=<epoch>
example command
python Mobile-Net.py --model_dir='./checkpoint/' --inp=resume --b_s=16 --e=100
python <Mobile-Net.py or Inception-Net.py > --model_dir=<Location for loading saved check point> --onnx_dir=< Location to save onnx model> --inp= <tune, train, test, resume, conv >
example command
python Mobile-Net.py --model_dir='./checkpoint/' --onnx_dir='./onnx/'--inp=conv
In this work the models are trained on cifar10 dataset with batch size 128 and 50 epochs. You can download the pretrained weights and place them at ./Inception_NET/checkpoint/ or ./M0bile_Net/checkpoint// for inferene or resume training using the above mentioned commands. The pretrained weights for Mobile net and Inception Net can be be downloaded from the folllowing links respectively.
https://drive.google.com/file/d/1OCxDNDUbMJcoo8QbzB6hM4r4yqXOXpZU/view?usp=sharing
https://drive.google.com/file/d/144j9-G-v2x6YCTZ4u9_NDzXpVnVwT_kC/view?usp=sharing
Test results and comparision for both models is shown in the following table
Model | Parameters | Acc.FineTune | Acc. Scratch | Latency(sec) | Size on Disk (MB) | Flops |
---|---|---|---|---|---|---|
Mobile-Net | 3,743,718 | 0.852 | 0.76 | 0.0004 | 38.89 | 0.116 G |
Inception-Net | 22,115,894 | 0.811 | 0.73 | 0.0006 | 174.2 | 0.681 G |
Thee confusion matrix for Mobile net is shown shown below
'airplane' | 'automobile' | 'bird' | 'cat' | 'deer' | 'dog' | 'frog' | 'horse' | 'ship' | 'truck' | |
---|---|---|---|---|---|---|---|---|---|---|
'airplane' | 728 | 18 | 75 | 20 | 63 | 3 | 30 | 1 | 49 | 13 |
'automobile' | 0 | 964 | 1 | 4 | 2 | 0 | 5 | 0 | 12 | 12 |
'bird' | 10 | 0 | 898 | 23 | 31 | 5 | 30 | 1 | 2 | 0 |
'cat' | 7 | 7 | 61 | 688 | 96 | 75 | 59 | 4 | 3 | 0 |
'deer' | 0 | 1 | 35 | 17 | 912 | 11 | 19 | 4 | 1 | 0 |
'dog' | 1 | 6 | 39 | 123 | 64 | 724 | 37 | 5 | 1 | 0 |
'frog' | 0 | 1 | 16 | 19 | 11 | 3 | 949 | 0 | 1 | 0 |
'horse' | 1 | 5 | 36 | 42 | 82 | 83 | 12 | 736 | 2 | 1 |
'ship' | 5 | 10 | 17 | 8 | 11 | 4 | 9 | 1 | 932 | 3 |
'truck' | 3 | 83 | 6 | 18 | 9 | 4 | 16 | 1 | 29 | 831 |
The confusion matrix for Inception net is shown below
'airplane' | 'automobile' | 'bird' | 'cat' | 'deer' | 'dog' | 'frog' | 'horse' | 'ship' | 'truck' | |
---|---|---|---|---|---|---|---|---|---|---|
'airplane' | 894 | 12 | 14 | 9 | 3 | 1 | 2 | 1 | 43 | 21 |
'automobile' | 7 | 933 | 1 | 2 | 2 | 0 | 3 | 0 | 27 | 25 |
'bird' | 103 | 7 | 742 | 63 | 23 | 19 | 30 | 5 | 6 | 2 |
'cat' | 27 | 3 | 50 | 765 | 33 | 66 | 19 | 5 | 19 | 13 |
'deer' | 21 | 3 | 82 | 67 | 769 | 14 | 13 | 5 | 20 | 6 |
'dog' | 10 | 8 | 32 | 207 | 31 | 687 | 6 | 5 | 7 | 7 |
'frog' | 18 | 4 | 42 | 55 | 18 | 14 | 828 | 0 | 19 | 2 |
'horse' | 19 | 4 | 27 | 70 | 66 | 73 | 8 | 715 | 3 | 15 |
'ship' | 29 | 8 | 6 | 5 | 1 | 1 | 1 | 1 | 933 | 15 |
'truck' | 25 | 74 | 4 | 7 | 0 | 4 | 1 | 3 | 32 | 850 |