
HyperTransformer
Image classification554 ops2.6M params
A Transformer that writes a small CNN's weights from a handful of labeled examples per class.
Image classification · 550 operations Checked
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.
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
About this model's family
HyperTransformer is a few-shot learner that does not fine-tune a classifier so much as write one: a Transformer reads the labeled support images and emits the weights of a small convolutional network directly. The motivation is capacity: with the task-dependent knowledge held in a high-capacity Transformer, the complexity of the whole task space is decoupled from the complexity of any single generated model. That matters most for tiny target networks, where a single fixed, task-independent embedding is not the best one can do.
Weights are produced layer by layer, starting from the first. Each layer's generator receives a concatenation of image embeddings, embeddings of the previous layer's activations and the support labels, so later layers are conditioned on what the already generated layers compute. Alongside the sample tokens, the input sequence holds learnable placeholder tokens, one per slice of the weight tensor to be generated, and their outputs are read off and assembled into the final weights. Self-attention is a deliberate choice because its output is invariant to the order of the support samples. Unlabeled support images can be added to the support set, turning the method semi-supervised without substantial changes to the model or training approach. The paper reports that accuracy grows with the number of unlabeled samples, and peaks only once the Transformer encoder has at least two layers.
Generating only the final logits layer is already enough to beat MAML++ and RFS for smaller CNNs. The margin narrows as the generated CNN grows, with large-model results comparable to those methods. Generating every convolutional layer rather than just the logits helped further, but only below a certain model size: at 8 channels the last layer alone was sufficient. The target networks are 4-layer CNNs identical to those used in MAML++ and many other papers. Batch-norm variables in those networks are learned, not generated. In the PyTorch port the captured members are built from, the Transformer stage takes a set of input embeddings and returns a set of output embeddings that contain the CNN weights.
Key idea. HyperTransformer replaces per-task fine-tuning with a Transformer that, given a few-shot episode, generates the weights of a small CNN in a single pass, trained end to end through the query-set loss.
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
@misc{zhmoginov2022hypertransformermodelgenerationsupervised,
title={HyperTransformer: Model Generation for Supervised and Semi-Supervised Few-Shot Learning},
author={Andrey Zhmoginov and Mark Sandler and Max Vladymyrov},
year={2022},
eprint={2201.04182},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2201.04182},
}