Intro
The best projects often arise from simple curiosities through exploring the world around us. I love finding questions that few people, if anyone, have asked before. On a family trip to the Smoky Mountains, nestled between North Carolina and Tennessee, I found myself enamored by the Tail of the Dragon. With its 318 curves over an 11-mile stretch, this road is a paradise for motor enthusiasts.
Businesses along the road capitalize on its popularity, snapping photos of passing vehicles and selling them to drivers online. I noticed the manual effort going into sorting every one of these images into categories like Porches, Mustangs, and Miatas, and in that I saw an opportunity: could machine learning automate this process?
Data Collection
Using Python’s BeautifulSoup for web scraping and Requests for image downloading, I compiled a dataset of around 500,000 images spanning 160 categories from the website. After manually merging categories together, I narrowed down to nine categories, BMW, Corvette/Camaro, Honda/Acura, Jeep, Miata, Mini, Mustang, Porsche, and VW/Audi. Some models or manufacturers are combined because that is how they are manually sorted in the website, Each group was filtered down to 30,000 images, culminating in a total dataset of 270,000 images. The data was split with an 80:20 ratio for training and validation.
Data Preprocessing
Given the variability in image compositions, data augmentation, modifying of images to improve performance, was key. I employed techniques like horizontal flips, rotations, zooms, and shears. Additionally, images were rescaled to have pixel values between 0 and 1 and resized to 300x200.
Model Training
Inspired by Albion Krasniqi’s research, I used the EfficientNetB1 neural network with pretrained ImageNet weights. Using the Adam optimizer and the categorical crossentropy loss function, the model was trained over 5 epochs.
Model Evaluation
The results were promising, with the model achieving high precision and recall for each category. The confusion matrix indicated occasional misclassifications, such as Miatas sometimes being identified as Corvettes or Jeeps.
precision | recall | f1-score | support | |
---|---|---|---|---|
bmw | 0.94 | 0.92 | 0.93 | 6000 |
corvette | 0.98 | 0.91 | 0.95 | 6000 |
honda | 0.92 | 0.95 | 0.93 | 6000 |
jeep | 0.99 | 1.00 | 0.99 | 6000 |
miata | 0.99 | 0.90 | 0.95 | 6000 |
mini | 0.99 | 0.99 | 0.99 | 6000 |
mustang | 0.93 | 0.96 | 0.94 | 6000 |
porsche | 0.92 | 0.95 | 0.93 | 6000 |
vw | 0.90 | 0.97 | 0.93 | 6000 |
accuracy | 0.95 | 54000 | ||
macro avg | 0.95 | 0.95 | 0.95 | 54000 |
weighted avg | 0.95 | 0.95 | 0.95 | 54000 |
Taking a look at 100 examples of misclassifications revealed the model struggled with heavily modified cars, challenging lighting conditions, black cars, rare models, and cars in unusual angles, distances, or strange composition.
Conclusion
With an overall accuracy of 95%, the model presents a promising solution to automate the classification of car photos from the Tail of the Dragon. While manual checks post-classification would be necessary initially, continuous optimization would only enhance the model’s efficiency. Future research could experiment with different pre-trained models or delve into designing a bespoke model.
Thank you for joining me on this fascinating journey through machine vision and mountain vistas!