Vehicle Classifier - Dude, What's My Car?
A fine-tuned EfficientNet-B4 model for identifying vehicle make, model, and year from photographs. Part of the "Dude, What's My Car?" vehicle identification system.
Model Description
This model classifies vehicles into 8,949 unique classes covering make, model, and year combinations. It was trained on the VMMRdb (Vehicle Make and Model Recognition) dataset.
Architecture
- Base Model: EfficientNet-B4 (via timm)
- Input Size: 380 x 380 pixels
- Output: 8,949 classes (format:
Make Model Year) - Parameters: ~19M
Performance
- Top-1 Accuracy: ~50%
- Top-5 Accuracy: ~75-80%
Note: Vehicle classification is challenging due to subtle differences between model years and trim levels. Top-5 accuracy is more meaningful for practical applications.
Intended Use
- Vehicle identification from photographs
- Automotive inventory management
- Insurance claim processing
- Law enforcement investigations
- Parking and traffic systems
Files
| File | Format | Size | Description |
|---|---|---|---|
vehicle_classifier.pth |
PyTorch | 130MB | Full checkpoint with weights + class mapping |
vehicle_classifier.onnx |
ONNX | ~1MB | Optimized for fast inference |
class_mapping.csv |
CSV | 346KB | Class ID to Make/Model/Year mapping |
Quick Start
PyTorch
import torch
import timm
from PIL import Image
from torchvision import transforms
# Load model
checkpoint = torch.load("vehicle_classifier.pth", map_location="cpu")
model = timm.create_model("efficientnet_b4", pretrained=False, num_classes=8949)
model.load_state_dict(checkpoint["model_state"])
model.eval()
# Preprocessing
transform = transforms.Compose([
transforms.Resize((380, 380)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
# Predict
image = Image.open("car.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
logits = model(input_tensor)
probs = torch.softmax(logits, dim=1)
top5_probs, top5_indices = torch.topk(probs, 5)
# Decode predictions
class_mapping = checkpoint["class_mapping"] # {id: "Make Model Year"}
for prob, idx in zip(top5_probs[0], top5_indices[0]):
print(f"{class_mapping[idx.item()]}: {prob.item()*100:.1f}%")
ONNX Runtime
import onnxruntime as ort
import numpy as np
from PIL import Image
# Load model
session = ort.InferenceSession("vehicle_classifier.onnx")
# Preprocess (same as PyTorch)
image = Image.open("car.jpg").convert("RGB").resize((380, 380))
img_array = np.array(image).astype(np.float32) / 255.0
img_array = (img_array - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
img_array = img_array.transpose(2, 0, 1)[np.newaxis, ...]
# Predict
outputs = session.run(None, {"input": img_array.astype(np.float32)})
logits = outputs[0]
# Get top predictions
probs = np.exp(logits) / np.sum(np.exp(logits), axis=1, keepdims=True)
top5_indices = np.argsort(probs[0])[-5:][::-1]
With Hugging Face Hub
from huggingface_hub import hf_hub_download
# Download model
model_path = hf_hub_download(repo_id="Jordo23/vehicle-classifier", filename="vehicle_classifier.pth")
onnx_path = hf_hub_download(repo_id="Jordo23/vehicle-classifier", filename="vehicle_classifier.onnx")
Training Details
- Dataset: VMMRdb (Vehicle Make and Model Recognition Database)
- Training Images: ~280,000
- Classes: 8,949 (Make + Model + Year combinations)
- Epochs: Fine-tuned from ImageNet pretrained weights
- Optimizer: AdamW
- Loss: Cross-Entropy
Limitations
- Best performance on clear, well-lit photographs
- May struggle with:
- Heavily occluded vehicles
- Unusual angles (top-down, extreme close-ups)
- Very old/rare vehicles not in training data
- Heavily modified or custom vehicles
- Color detection is handled separately (not part of this model)
Citation
If you use this model, please cite:
@misc{vehicle-classifier-2024,
author = {Jordo23},
title = {Vehicle Classifier - Dude, What's My Car?},
year = {2024},
publisher = {Hugging Face},
url = {https://huggingface.co/Jordo23/vehicle-classifier}
}
License
MIT License - Free for personal and commercial use.
Contact
For issues or questions, please open an issue on the model repository.
Part of the "Dude, What's My Car?" vehicle identification system ๐
- Downloads last month
- -