π TwinCar: Fine-Grained Car Classification (Stanford Cars 196)
This model predicts car make and model from images using a fine-tuned ResNet50 architecture, trained on the Stanford Cars 196 dataset.
Final project for Brainster Data Science Academy 2025.
π Project Overview
- Task: Classify car images into 196 make/model categories
- Context: Automated vehicle inspection for TwinCar (drones/robots)
- Input: RGB image (JPG/PNG, 224x224 or similar)
- Output: Predicted car make/model (e.g., "BMW X5")
- Production goal: Identify car brand/model for real-world inspection/automation
ποΈ Model Details
- Architecture: ResNet50 (PyTorch, transfer learning, custom head)
- Classes: 196 (make/model, see
test_labels.csv
) - Dataset: Stanford Cars 196
- Training: 15 epochs, batch size 32, strong data augmentation
- Authors: Kiril Mickovski & Team 3 (Brainster DSA)
- License: MIT
Metrics & Results
Metric | Value | Description |
---|---|---|
Validation Accuracy | 40.6% | Correct predictions on the validation dataset |
Training Accuracy | 74.4% | Correct predictions on the training dataset |
Validation Loss | 3.07 | Cross-entropy loss on validation set |
Training Loss | 1.74 | Cross-entropy loss on training set |
Macro F1-score | 0.38 | Harmonic mean of precision and recall across all classes |
Macro Precision | 0.44 | Average precision over all classes |
Macro Recall | 0.41 | Average recall over all classes |
Full per-class metrics: classification_report.csv
π Model Evaluation & Explainability
Below are selected screenshots and artifacts showcasing model evaluation, predictions, and explainability:
π΅ Confusion Matrix
π’ Training & Validation Curves
π£ F1, Precision, Recall Curves
π Top-20 Most Accurate Classes
π‘ Top-20 Most Confused Classes
π΄ Grad-CAM++ Examples (Explainability)
Model attention visualizations for interpretability (what parts of the image the model βlooks atβ):
π Files & Artifacts
resnet50_finetuned.pth
β Model weightsclassification_report.csv
β Per-class metricstest_predictions_named.csv
β Sample predictionsrequirements.txt
β Dependencies for inference- All PNGs β Visualizations, explainability, confusion matrix, curves, etc.
π οΈ How to Reproduce
- Clone this repo or download weights and artifacts from above.
- Install dependencies:
pip install -r requirements.txt
- Run the usage code (see Usage section above) or visit the GitHub repo for end-to-end training and evaluation.
β οΈ Limitations
- Only 196 classes covered (see Stanford Cars dataset)
- Performance may drop on night images, occlusions, or cars outside the 2010β2012 range
- Trained for car make/model only (not year)
π₯ Contributors
- Kiril Mickovski
- Team 3, Brainster Data Science Academy 2025
π Citation
Mickovski, K., Team 3 (2025). TwinCar: Fine-Grained Car Classification (Stanford Cars 196). Brainster Data Science Academy.
π Resources
π§βπ» Usage (PyTorch)
import torch
from torchvision import models, transforms
from PIL import Image
model = models.resnet50()
model.fc = torch.nn.Linear(model.fc.in_features, 196)
model.load_state_dict(torch.load("resnet50_finetuned.pth", map_location="cpu"))
model.eval()
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
img = Image.open("your_image.jpg").convert("RGB")
input_tensor = transform(img).unsqueeze(0)
with torch.no_grad():
logits = model(input_tensor)
pred = logits.argmax(1).item()
Model tree for kikogazda/TwinCar-196
Base model
timm/resnet50.a1_in1k