Relation Networks
What you'll learn: How to learn a more powerful, flexible similarity metric using a neural network instead of fixed distance functions.
Beyond Fixed Distances
In Prototype Networks and Matching Networks, we compared embeddings using fixed distance metrics like Euclidean distance or cosine similarity. But what if similarity itself could be learned? That's exactly what Relation Networks do.
The Core Idea
Instead of using a predetermined distance function, Relation Networks train a small neural network (called the relation module) to compute similarity scores between support and query embeddings.
Think of it like this: rather than using a ruler to measure distance (fixed metric), you're training an expert judge who learns what "similar" means for your specific task. This judge sees many examples during episode-based training and learns nuanced patterns that simple distance calculations might miss.
How It Works
- Embedding: Pass support and query images through a shared embedding network (just like before)
- Concatenation: For each support-query pair, concatenate their embeddings into a single vector
- Relation Module: Feed this concatenated vector through a small neural network that outputs a similarity score (typically 0-1)
- Prediction: The query's predicted class is the support example with the highest relation score
The relation module is usually a simple feedforward network or a few convolutional layers — nothing fancy, but trainable end-to-end alongside the embedding network.
Why This Matters
Learning the metric gives the model flexibility to discover complex, non-linear relationships between embeddings that fixed distances can't capture. It's particularly powerful when visual similarity doesn't correspond neatly to Euclidean space.
Key Takeaway: Relation Networks replace fixed distance metrics with a learned neural network that computes similarity scores, allowing the model to discover task-specific notions of "similar" through meta-training.