Views
No views yet
TwinCar is an advanced deep learning pipeline designed for precise car make/model recognition using the Stanford Cars 196 dataset.
Features: Transfer learning, robust augmentation, Grad-CAM++ explainability, metric-rich evaluation, and easy deployment.
Developed at Brainster Data Science Academy, 2025.
twin_car_best_model_v2.pth)class_mapping.json)





| Metric | Value |
|---|---|
| Train Loss | 0.98 |
| Train Accuracy | 99.7% |
| Val Loss | 1.72 |
| Val Accuracy | 79.1% |
| Val Precision (macro) | 82.4% |
| Val Recall (macro) | 79.1% |
| Val F1 (macro) | 78.5% |
| Cohen’s Kappa | 0.79 |
| MCC | 0.79 |
| Top-3 Accuracy | 90.9% |
| Top-5 Accuracy | 93.4% |
1pip install -r requirements.txt
2pip install pytorch-grad-cam gradio
3
42. Run Inference
5python
6Copy
7Edit
8import torch
9from torchvision import models, transforms
10from PIL import Image
11import json
12
13# Load model
14model = models.resnet50(weights=None)
15model.fc = torch.nn.Sequential(
16 torch.nn.Linear(model.fc.in_features, 512),
17 torch.nn.ReLU(),
18 torch.nn.Dropout(0.2),
19 torch.nn.Linear(512, 196)
20)
21model.load_state_dict(torch.load("twin_car_best_model_v2.pth", map_location="cpu"))
22model.eval()
23
24# Preprocess
25transform = transforms.Compose([
26 transforms.Resize((224, 224)),
27 transforms.ToTensor(),
28 transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
29])
30img = Image.open("your_image.jpg")
31input_tensor = transform(img).unsqueeze(0)
32
33# Predict
34with torch.no_grad():
35 output = model(input_tensor)
36 pred = output.argmax(1).item()
37
38# Class name
39with open("class_mapping.json") as f:
40 class_map = json.load(f)
41print("Predicted class:", class_map[str(pred)])