dynamicguy / stanford-cars-model

A PyTorch model for Stanford Cars Datasets: https://ai.stanford.edu/~jkrause/cars/car_dataset.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stanford-cars-model (under development)

A PyTorch model for Stanford Cars Classification

Dependencies

  • python 3.7
  • pytorch
  • scikit-image
  • numpy
  • opencv-python
  • tensorboard

Install

Extract training & testing data using annotation bounding box

Data Prepare

data_processing/
│
├── datasets/ - folder contain training & testing data
    ├── cars_metas/ - folder contain meta data for training & testing
        ├── cars_train_annos.mat - train meta
        ├── cars_test_annos_withlabels.mat - test meta
    ├── training/
        ├── original/ - original cars from training data
          ├── 00001.jpg
          ├── 00002.jpg
          ├── 00003.jpg
          ├── 00004.jpg
          ├── ...
        ├── extracted/ - cars after extracted using bounding box label
    ├── testing/
        ├── original/ - original cars from testing data
          ├── 00001.jpg
          ├── 00002.jpg
          ├── 00003.jpg
          ├── 00004.jpg
          ├── ...
        ├── extracted/ - cars after extracted using bounding box label
        

Training data download: http://ai.stanford.edu/~jkrause/car196/cars_train.tgz

Testing data download: http://ai.stanford.edu/~jkrause/car196/cars_test.tgz

After download, extract and copy image to data_processing/datasets/training/original and data_processing/datasets/testing/original

Data Extract

Standford Cars Dataset come with annotated label, so we would like to use it to extract only cars and remove background. This help our model focus only on vehicles

For training:

cd data_processing
python extract_cars.py --meta "datasets/cars_metas/cars_train_annos.mat" -input "datasets/training/original/ -output "datasets/training/extracted/"

For testing:

cd data_processing
python extract_cars.py --meta "datasets/cars_metas/cars_test_annos_withlabels.mat" -input "datasets/testing/original/ -output "datasets/testing/extracted/"

Training

The model contain:

  • ResNet 151
  • Cyclic Learning Rate: default from 0.01 to 0.1
  • Auto Augmentation with ImageNet pretrained

You can start training model imediately with the following script:

python train.py -c train_config.json

Resuming

python train.py -c train_config.json -r "path/to/model.pth"

Visualization

alt text

Testing

You can download pretrained model here: https://www.dropbox.com/s/w550z44ur2pwr4j/model_best.pth?dl=0

And run following script with downloaded model to predict classes on test set

python test.py -c test_config.json -m "model_best.pth" -o "test_output/"

Final result

Test Accuracy: 93.4%

About

A PyTorch model for Stanford Cars Datasets: https://ai.stanford.edu/~jkrause/cars/car_dataset.html

License:MIT License


Languages

Language:Python 94.5%Language:Jupyter Notebook 5.5%