Teaching neural networks to eyeball similarity
A 2018 CVPR implementation that learns a learnable distance metric for few-shot image classification instead of relying on fixed metrics like cosine distance.

What it does
This repo implements Relation Network for few-shot learning: given a handful of examples of a new image class (one or five shots), the model learns to classify query images by computing a learned “relation score” between support and query samples. It includes training and test scripts for Omniglot and mini-Imagenet benchmarks with standard N-way K-shot splits.
The interesting bit
Most few-shot methods at the time used fixed distance metrics (cosine, Euclidean) in embedding space. This work treats the comparison itself as a learnable module—a small CNN that takes concatenated support-query embeddings and outputs a similarity score. The insight: even a good embedding space benefits from a learned comparator tuned to that space.
Key highlights
- Supports Omniglot (5-way/20-way, 1-shot/5-shot) and mini-Imagenet (5-way, 1-shot/5-shot) experiments
- Includes pre-trained models that load by default; delete them to train from scratch
- Omniglot data (28×28 resized) bundled in-repo; mini-Imagenet requires manual download and preprocessing via
proc_image.py - Based on MAML’s data processing pipeline, with clear reference links
- Straightforward CLI:
-wfor ways,-sfor shots,-bfor batch size (tune to GPU memory)
Caveats
- Requires Python 2.7 and PyTorch 0.3—both long past end-of-life, expect friction modernizing
- No mini-Imagenet data included; Google Drive link may be stale
- README is minimal: no results table, no architecture diagram, no dependency versions beyond PyTorch
Verdict
Worth studying if you’re researching metric learning or few-shot architectures and want a clean reference implementation of a seminal comparison-based approach. Skip if you need production-ready code; this is research archaeology with 2018-era dependencies.