CoolFace
Apppublic

Yoad22/imagenette-recommender

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

Imagenette Visual Recommender

Dataset: frgfm/imagenette - 10-class ImageNet subset, 13,394 images Model: openai/clip-vit-base-patch32 - 512-dimensional embeddings Space: https://huggingface.co/spaces/Yoad22/imagenette-recommender


What This Is

A visual recommendation system that takes an uploaded image (or a text description) and returns the 3 most visually similar images from a pool of 13,394 Imagenette photos. Powered by CLIP ViT-B/32 embeddings and cosine similarity.

Classes: tench, English springer, cassette player, chain saw, church, French horn, garbage truck, gas pump, golf ball, parachute.


Key Results

MetricValue
Total images embedded13,394
Embedding dimension512
Same-class cosine similarity0.688
Cross-class cosine similarity0.457
KMeans silhouette score (k=10)0.2884
Overall cluster purity98.0%
PCA variance explained (50 components)70.5%

The silhouette score of 0.2884 and cluster purity of 98% confirm that CLIP embeddings organise the 13,394 images into semantically meaningful groups without any label supervision.


Dataset Sample

One representative image per class, showing the visual diversity across the 10 categories.

[image]


Exploratory Data Analysis

RQ1 - Class Distribution

The dataset is perfectly balanced at roughly 960 images per class. No class dominates the recommendation pool.

[image]

RQ2 - Image Dimensions and Aspect Ratios

Most images have their longest side at 320px with the other axis in the 213-320px range, reflecting the longest-side resize applied by the dataset. Aspect ratios are consistent across classes so CLIP center-crop preprocessing treats all categories equally.

[image]

RQ3 - Brightness per Class

Golf balls and gas pumps are among the brightest classes; chain saws and garbage trucks score lower. Brightness carries partial class signal but classes overlap heavily, confirming it cannot separate categories on its own.

[image]

RQ4 - Mean Color per Class

Tench images have a distinctly greenish-blue mean color from their aquatic settings. Several classes share similar neutral palettes, further motivating the use of semantic embeddings over raw pixel statistics.

[image]

RQ5 - Sharpness per Class

Golf balls and chain saws show higher Laplacian variance, consistent with close-up photography of objects with crisp edges. Wide interquartile ranges across all classes confirm sharpness is not a stable class discriminator.

[image]

RQ6 - Pixel-Level Inter-Class Similarity

Even between visually distinct classes, raw pixel cosine similarity remains above 0.85. This confirms that pixel-level matching cannot reliably separate categories and directly motivates the CLIP embedding approach.

[image]


Embeddings and Clustering

PCA Explained Variance

50 principal components capture 70.5% of the variance in the 512-dimensional embedding space, providing an effective denoising step before t-SNE.

[image]

t-SNE vs PCA 2D Projection

The t-SNE projection (left) shows 10 tight, well-separated clusters that map directly onto the 10 ground-truth classes. The PCA 2D projection (right) shows less separation, confirming the embedding geometry is complex and non-linear.

[image]

KMeans Clusters (k=10) on t-SNE

KMeans discovers the true class structure without any label supervision. Silhouette score: 0.2884. Overall cluster purity: 98.0%.

[image]


Recommendation Demo

Query image on the left. Top 3 most similar images on the right with class name and cosine similarity score.

[image]


How It Works

  1. 1.All 13,394 images are embedded offline using CLIP ViT-B/32 and stored in a parquet file
  2. 2.At query time the uploaded image (or text description) is embedded using the same model
  3. 3.Cosine similarity is computed between the query vector and all 13,394 stored vectors
  4. 4.The top 3 results are returned with class names and similarity scores

Text queries work because CLIP aligns image and text in the same 512-dimensional space.