Car Model Classification. In this post I will show the result for... | by Weng Seng | Towards Data Science

In this post I will show the result for car model classification with ResNet ( Residual Neutral Network). I use Python and Pytorch to build the model. The steps were similar to my previous flower species classifier project so I will brief about some key steps and the result.
You can check my github repo here.
I download the Stanford car dataset from Kaggle by using Kaggle API and save in my google drive.
# The Kaggle API client expects this file to be in ~/.kaggle,!mkdir -p ~/.kaggle!cp kaggle.json ~/.kaggle/# This permissions change avoids a warning on Kaggle tool startup.!chmod 600 ~/.kaggle/kaggle.json#mount my gdrivefrom google.colab import drivedrive.mount('/content/drive')#download the dataset!kaggle datasets download -d jutrera/stanford-car-dataset-by-classes-folder#unzip the file!unzip stanford-car-dataset-by-classes-folder.zip
The Cars dataset contains 16,185 images of 196 classes of cars. The data is split into 8,144 training images and 8,041 testing images.
Transfer learning make use of the knowledge gained while solving one problem and applying it to a different but related problem.The pre-trained model here is ResNet( Residual Neutral Network).
Artificial Neural Network predicts the outcome by learn through the examples and previous experiences. Artificial Neural Network computations carried out in parallel and create their own representation of information which they receive during the learning time. In the artificial Neural Network, just add in one more layer which is convolutional layer.
For further explanation about ResNet architectures you can refer here.
Back to our case here, we got 196 classes of cars as the total number of outputs so we need change the output layer into 196.
num_ftrs = model.fc.in_featuresmodel.fc = nn.Linear(num_ftrs, 196)
I have try few parameter and keep running epochs for quite a few times. In the end with 10 epochs it give us 77.72% validation accuracy give me the best so far I tried. The training process really time consuming just need to be patient. Cheer!
Let see what it actually did!!
For the Mercedes-Benz S-Class Sedan 2012 the model predicted Mercedes-Benz E-Class Sedan 2012 which is inaccurate. The Mercedes-Benz S-Class Sedan 2012 also didn’t appear in the top 5 predicted classes.BMW X6 SUV 2012 predicted semi-correctly because it appeared in third top classes. It supposed be the top classes in the prediction result not the Ford Fiesta Sedan 2012.
Hyundai Veloster Hatchback 2012 and Volkswagen Golf Hatchback 2012 were well predicted with more than 30%.
Both are BMW 3 Series Sedan 2012 just the different is the angle view. The left image is front view and the right image is rear view. Surprisingly both different view of BMW 3 predicted correctly. The top 5 prediction result in the left side was very good because it predicted the top 5 classes were all BMW. In the right side result also good, BMW appeared in the top 3.
However, in this case BMW M5 Sedan 2010 does not performing, it got all top 5 prediction classes wrong. Any BMW car model did not show up in the result.
In this case both model were SUV models and predicted correctly.