Downloads · 30 days
0
PatrickBLB/egyptian_cars_recognition_computer_vision_model
egyptian_cars_recognition_computer_vision_model is a image classification model from PatrickBLB. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as cc-by-nc-4.0.
A fine-grained image classifier that identifies the make, model, and production generation of cars from a single photo. Trained on 1211 distinct car generations, with a price-mapping companion dataset of cars commonly…
Downloads · 30 days
0
Access
Public
Updated May 17, 2026
Repo size
87.8 MB
Likes
0
Public
Click a slice to open those files.
.pt87.8 MB · 100%
From the Hugging Face model README
A fine-grained image classifier that identifies the make, model, and production generation of cars from a single photo. Trained on 1211 distinct car generations, with a price-mapping companion dataset of cars commonly sold in the Egyptian market.
| Architecture | EfficientNetV2-S (PyTorch, torchvision) |
| Parameters | 21.7M |
| Input size | 300×300 RGB |
| Output | 1211-class softmax (one class per car generation) |
| Pretrained on | ImageNet-1K |
| Fine-tuned on | Custom 1211-class car dataset (~257K images) |
Evaluated on a held-out test set of 26,818 images (10% stratified split):
| Metric | Score |
|---|---|
| Test Top-1 Accuracy | 59.85% |
| Test Top-5 Accuracy | 92.02% |
| Validation Top-1 | 59.72% |
| Validation Top-5 | 91.88% |
For context: random guessing on 1211 classes yields 0.083% accuracy. The model performs ~720× better than random on top-1, and finds the correct generation in its top-5 guesses 92% of the time.
Suitable for:
Not suitable for (without further validation):
Classes are named in the format: Company_Model_BeginYear_EndYear
Examples:
Toyota_Camry_2018_2024Honda_Civic_2016_2021BMW_3-Series_2012_2018The full list is available in class_names.json. Each class represents a generation (typically 5-8 years of production with the same overall design), not individual model years.
pip install torch torchvision pillow huggingface_hub
import json
import torch
import torch.nn as nn
from PIL import Image
from torchvision import transforms
from torchvision.models import efficientnet_v2_s
from huggingface_hub import hf_hub_download
# Download model files
REPO_ID = "PatrickBLB/egyptian_cars_recognition_computer_vision_model"
model_path = hf_hub_download(repo_id=REPO_ID, filename="efficientnet_v2s_cars.pt")
classes_path = hf_hub_download(repo_id=REPO_ID, filename="class_names.json")
# Load class names
with open(classes_path, "r") as f:
class_names = json.load(f)
# Build and load model
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
checkpoint = torch.load(model_path, map_location=device, weights_only=False)
model = efficientnet_v2_s(weights=None)
model.classifier[1] = nn.Linear(model.classifier[1].in_features, len(class_names))
model.load_state_dict(checkpoint["model_state"])
model.to(device).eval()
# Prepare image
transform = transforms.Compose([
transforms.Resize((300, 300)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
img = Image.open("your_car_image.jpg").convert("RGB")
tensor = transform(img).unsqueeze(0).to(device)
# Predict
with torch.no_grad():
probs = torch.softmax(model(tensor), dim=1)
top5_probs, top5_idx = probs.topk(5, dim=1)
for prob, idx in zip(top5_probs[0], top5_idx[0]):
print(f"{class_names[idx]:<40} {prob.item()*100:.2f}%")
See inference_example.py for a more complete example, including price mapping.
Company_Model_BeginYear_EndYear (e.g., Toyota_Camry_2018_2024)| Hyperparameter | Value |
|---|---|
| Optimizer | AdamW |
| Learning rate | 1e-3 (peak) |
| Weight decay | 1e-4 |
| Loss | CrossEntropyLoss with class weights + label smoothing (0.1) |
| Sampler | WeightedRandomSampler (class-balanced) |
| Batch size | 32 |
| Epochs | 20 |
| LR schedule | 1-epoch linear warmup + cosine decay |
| Augmentation | RandomCrop, HorizontalFlip, ColorJitter |
| Training hardware | Apple M5 (MPS backend) |
| Training time | ~44 hours (~2.17 hours/epoch) |
Two techniques were combined to address the 23.5× class imbalance:
Together these ensure rare classes receive sufficient training signal despite their small population.
This model can be paired with a companion CSV (combined_cars.csv) containing average prices in Egyptian Pounds (EGP) for cars commonly sold in the Egyptian market. The CSV uses the same combined_title format as the model's class labels, enabling direct lookup of an estimated price from a predicted class.
See the inference script for an example of how to combine classification output with price lookup.
This model is released under CC BY-NC 4.0 (Creative Commons Attribution-NonCommercial 4.0 International).
You are free to:
You may not:
If you use this model in your work, please cite:
@misc{patrickblb2026egyptiancars,
author = {Patrick BLB},
title = {Egyptian Cars Recognition: EfficientNetV2-S Fine-Grained Classifier (1211 classes)},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/PatrickBLB/egyptian_cars_recognition_computer_vision_model}
}
For questions, issues, or licensing inquiries: @PatrickBLB on Hugging Face