All Projects

2025

BEiT vs. MatchNet — Deep Learning for Image Similarity

Comparison of two deep learning approaches for patch-based image similarity classification using Tiny ImageNet, achieving 94% accuracy with MatchNet and 89% with BEiT.

With Arvind Nair·Tenzin Shenyen·Sanskruti Mali

Python PyTorch Tiny ImageNet BEiT Cosine Similarity
BEiT vs. MatchNet — Deep Learning for Image Similarity — image 1
BEiT vs. MatchNet — Deep Learning for Image Similarity — image 2
BEiT vs. MatchNet — Deep Learning for Image Similarity — image 3
BEiT vs. MatchNet — Deep Learning for Image Similarity — image 4
BEiT vs. MatchNet — Deep Learning for Image Similarity — image 5
BEiT vs. MatchNet — Deep Learning for Image Similarity — image 6

The Problem

Given two images from the Tiny ImageNet dataset (200 classes), predict whether they belong to the same class — a binary similar / dissimilar classification evaluated across over 12 million image pairs.

What We Built

Two independent deep learning approaches were built and compared head-to-head:

  • MatchNet — a Siamese-style CNN trained from scratch. A shared feature extractor maps each image into a compact embedding; a learned metric network then outputs a similarity score. Trained end-to-end with Binary Cross-Entropy loss.

  • BEiT (BERT Pre-Training of Image Transformers) — a Vision Transformer pretrained via masked image modeling, where ~40% of 16×16 patches are masked and the model learns to predict their discrete visual tokens. Fine-tuned on the pairwise similarity task using the same BCE objective.

Both models were evaluated across multiple learning rates and batch sizes. MatchNet’s best configuration used LR = 0.0001; BEiT’s best used LR = 5e-5, batch size = 64.

Results

Tested on 12,115,503 image pairs from Tiny ImageNet:

ModelAccuracyBest Config
MatchNet94.28%LR = 0.0001
BEiT89.14%LR = 5e-5, BS = 64

MatchNet outperformed the pretrained transformer — likely because the metric learning objective trained end-to-end aligns directly with the similarity task, while BEiT’s general-purpose pretraining introduces a domain gap that fine-tuning alone doesn’t fully close.