Fastai Car Type Classification Model Using a Custom Dataset

Aravinda 加阳
unpack
Published in
5 min readMar 22, 2021

--

I’m going to create a car type classification model using a custom dataset created from google images.

https://www.stemmer-imaging.com/en/knowledge-base/CVB-polimago-vs-deep-learning/

Dataset:
I collected more than 850 images from google images belong to three classes;
Sedan, Pickup, and Convertible. Since downloaded images contain some non-car images (images of text, people, etc.), I cleaned them first.

First I selected two classes; Sedan and Pickup and fit the model to those images. The body shape of a sedan and a pickup is significantly different from each other, if the model works fine it should be able to recognize these correctly.

Here I chose ResizedMethod.Squish because in classification it’s important to see the whole body of the car.

I trained for few epochs, it seems the model works fine. The model can recognize Sedan and Pickup correctly most of the time.

When checking the top losses, we can see that when the model can’t see the whole body of the car clearly, it classifies incorrectly.

Then I added the Convertable class. Ran learning rate finder.

Trained for 10 epochs.

In the 3rd epoch, the model starts to overfit. In the Confusion matrix, too many convertibles and pickups are classified as sedans. The error rate is 23%.

Trained for fewer epochs.

In the 3rd epoch, the model starts to overfit. But the confusion matrix is a little bit better than the previous one. The error rate is 21%.

Train fewer epochs.

Got better results for convertible and pickup but worse for the sedan. The error rate is 18%.

Data augmentation

Since the model starts to overfit within few epochs, I cleaned the data again and added data augmentation transformations.

Ran the learning rate finder.

Trained for few epochs.

So far I got an error rate of 7%. This confusion matrix is much better than the baseline. Most of the images are classified correctly with an accuracy of about 93%.

Then I did more training.

Finally, after tuning the learning rate and the number of epochs for few more times, reached the error rate of 5%. Most of the images are classified correctly with an accuracy of about 95%.

Update:

I added a new class Station Wagon in addition to Sedan, Pickup, and Convertible classes. Altogether dataset contains about 1100 car images. After adding data augmentation transformers and using unfreeze() method to unfreeze the whole network and continuous training, I could able to reach 93% validation accuracy.

Confusion Matrix

Conclusion:
In-car type classification it’s important to see the whole body of the car otherwise it’s hard to decide which type of a car it is.

Reference:

https://www.stemmer-imaging.com/en/knowledge-base/CVB-polimago-vs-deep-learning/

https://www.pyimagesearch.com/2017/12/04/how-to-create-a-deep-learning-dataset-using-google-images/

--

--