All models

RelationNet-fewshot

A few-shot image classifier that learns to compare a query image with a few examples of each class.

Image classification · 52 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (57 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
228.7K
Operations
52
Framework
PyTorch
Recurrent
Yes
Published
CVPR 2018
Cited by
807 (as of 23 October 2026)
Authors
Flood Sung, Yongxin Yang, Li Zhang and others
License
MIT
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m2580
Graph hash
6274c61acdb105a414b2af80286c3f34e8b8c41d3dfd84b4f8bf5aed6ddbfd62
Skeleton hash
e66e372a4dbe5ae18dd51f540202a208fd9eb842514c4e225172049634b834c2
Architecture hash
9b2b64a26e3156e3e8481ae4f6e05815b73b98440f86d77a348467ee47b97a92
Diagram SHA-256
fc6e9bf8dbfe32958d16fe7f052c2242e5cfef544cfbcfbf0bada6858d775786
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

The Relation Network (RN) is a few-shot image classifier: it learns to recognize new classes from only a few examples of each. Earlier metric-based methods learned an embedding and compared it with a fixed metric, and this paper learns the comparison as well.

The network has two modules, an embedding module and a relation module. The embedding module turns the query image and the sample images into feature maps, which are combined and passed to the relation module to produce a relation score between 0 and 1 for each pair. When a class has several examples their embeddings are summed element-wise into one class-level feature map, so a query always receives one score per class.

The relation module consists of two convolutional blocks and two fully-connected layers. Training uses mean square error, with a target of 1 for matched pairs and 0 for mismatched pairs. The authors call this choice of MSE somewhat non-standard. Once trained, the network classifies images of new classes without further updating its weights.

Key idea. The paper replaces the fixed distance metric of earlier few-shot methods with a learned relation module that scores how well a query image matches each class.

  • relation network
  • relationnet
  • rn
  • learning to compare
  • few-shot learning
  • few-shot classification
  • zero-shot learning
  • metric learning
  • meta-learning

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{sung2018learningcomparerelationnetwork,
      title={Learning to Compare: Relation Network for Few-Shot Learning}, 
      author={Flood Sung and Yongxin Yang and Li Zhang and Tao Xiang and Philip H. S. Torr and Timothy M. Hospedales},
      year={2018},
      eprint={1711.06025},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/1711.06025}, 
}