almador2002/Cars196
<div align="center">
π Cars196 β Visual Recommendation System
Find visually similar cars from an image or a text description
    
A CLIP-powered visual recommender that finds the 3 most similar cars to any input β using 512-dimensional joint image-text embeddings and cosine similarity.
</div>
π― What This Does
Upload a car photo or type a natural-language description β the app returns the 3 most visually similar cars from a dataset of ~8,000 vehicles spanning 196 fine-grained classes.
πΉ Presentation Video
<div align="center">
<!-- Replace YOURVIDEOID with the actual YouTube video ID after uploading --> 
Click the thumbnail above to watch the full 5-minute walkthrough on YouTube
</div>
π§ Tech Stack at a Glance
<div align="center">
</div>
πΊοΈ The Full Journey
The complete analytical pipeline lives in Assignment_3_Cars196.ipynb. Here are the highlights.
π Part 1 β Dataset Exploration
Cars196 is a fine-grained classification benchmark containing 16,185 images of 196 car classes, where each class corresponds to a specific Make + Model + Year combination (e.g., "BMW 3 Series Sedan 2012"). We use the training split (~8,144 images).
π Part 2 β Exploratory Data Analysis
A deep dive into the dataset's structure β class balance, manufacturer distribution, body types, production years, and image dimensions.
Key findings
- π¦ Roughly balanced β ~40 images per class on average
- π American and European manufacturers dominate the dataset
- π Sedans, coupes, and SUVs are the most represented body types
- π Cars range from 1991 to 2012 β with a heavy skew toward 2007-2012
𧬠Part 3 β Embeddings & Clustering
All ~8,000 car images were passed through CLIP ViT-B/32, producing L2-normalized 512-dimensional vectors.
3.1 β Dimensionality Reduction
Compared PCA, t-SNE, and UMAP side by side:
UMAP produced the most semantically meaningful clusters β visually similar cars (same body type, similar proportions) end up close together regardless of brand.
3.2 β Clustering
Applied two complementary clustering algorithms:
3.3 β Cluster Interpretation
CLIP embeddings cluster cars primarily by:
- π Body type / silhouette β the strongest signal (SUVs together, sedans together, sports cars together)
- π¨ Visual style & proportions β low-slung sports cars separate from tall boxy SUVs
- π‘ Color & lighting tendencies β backgrounds & palettes influence proximity
- π Size category β compact cars, mid-size sedans, and full-size vehicles form distinct groups
Verdict β are the clusters useful? Yes. They capture the visual feel of a car rather than just its brand name. A user looking for a sporty coupe naturally finds similar cars across BMW, Audi, and Porsche β exactly what a recommender should do.
π― Part 4 β The Recommendation Engine
User Input (image or text)
β
CLIP encoder
β
512-D vector (L2-normalized)
β
Cosine similarity vs. all 8,144 stored embeddings
β
β β single matrix multiplication
β
Top-3 ranked matchesImage Search Test
Text Search Tests
CLIP's killer feature: text and images live in the same vector space, so a phrase like "red sports car" can match images directly with no extra training.
π Bonus Analyses
Beyond the assignment's core requirements, the notebook explores a few extras:
1. Body Type Similarity Heatmap
How similar are different body types in CLIP's vector space? Sedans and coupes are close; trucks and convertibles are far apart.
2. Embedding Interpolation
Linearly interpolating between a Sedan and a Convertible in the embedding space β and watching the nearest car at each step morph from one to the other.
3. Nearest Neighbor Exploration
For a random query car, what are its closest neighbors in embedding space?
βοΈ Ethical Considerations
A few things to keep in mind about this system:
- Dataset bias β Cars196 is heavily skewed toward American and European brands. Asian manufacturers (Toyota, Honda, Hyundai) are underrepresented, which biases recommendations toward Western models.
- Temporal bias β Most cars in the dataset are from 2007β2012. The system won't recognize modern (2020+) designs well.
- Environmental angle β A more responsible recommender could highlight fuel efficiency or electric alternatives. This system is purely visual β it doesn't consider environmental impact.
- Privacy β Uploaded images are processed in-memory and never stored. In a production setting, users should be explicitly informed about data handling.
π Repository Contents
cars196-recommender/
βββ app.py # The Gradio application
βββ requirements.txt # Python dependencies (pinned for HF Spaces compatibility)
βββ README.md # β You are here
βββ car_embeddings.parquet # Pre-computed 512-D embeddings + metadata
βββ car_images.pkl # Compressed thumbnails for display
βββ Assignment_3_Cars196.ipynb # Full notebook (EDA β embeddings β clustering β recommendations)π οΈ How to Run Locally
git clone https://huggingface.co/spaces/YOUR_USERNAME/cars196-recommender
cd cars196-recommender
pip install -r requirements.txt
python app.pyThen open http://localhost:7860 in your browser.
π Acknowledgments & References
- CLIP β Radford et al., Learning Transferable Visual Models From Natural Language Supervision (paper)
- Cars196 / Stanford Cars β Krause et al., 3D Object Representations for Fine-Grained Categorization (paper)
- UMAP β McInnes et al., Uniform Manifold Approximation and Projection (paper)
- HuggingFace Datasets β for distributing Cars196 in a clean, accessible format
- Gradio β for making ML demos trivially easy to share
<div align="center">
Built for Assignment #3 β RecSys, Embeddings & Spaces
π€ Hosted on HuggingFace Spaces β’ π§ Powered by CLIP β’ π Made with Gradio
</div>
