Self-supervised learning
Pretext tasks, contrastive learning (SimCLR, NT-Xent), MoCo and masked image modelling; the linear probe measures what the learned representations are worth.
From labels to a pretext
The topic Semantic segmentation closed the convolutional module: every network there learned from labels — a class per image, a box, or a class per pixel. Labels are the expensive part of a dataset; pixel masks are the most expensive of all. Unlabelled photographs cost almost nothing.
Self-supervised learning trains a network on images alone. The training target is computed from the image itself. Afterward the features are reused on the task that has labels. A supervised ImageNet backbone works, but it learns only what the thousand class names ask for. The question of this topic is whether images alone can train a backbone whose features are as useful.
An encoder maps an image to a representation . A pretext task is a prediction problem solved only as a means to good . What is worth is measured later, on a labelled protocol.
Pretext tasks and shortcuts
The first pretext tasks transform the image in a known way and ask which transformation was applied.
Rotation. Each image is rotated by , , or , and the network classifies the angle. To tell which way is up it must find the object and its parts.
Jigsaw. The image is cut into a grid, the tiles are shuffled by one of a fixed set of permutations, and the network classifies which permutation it was. Of orders the authors keep a subset of that differ in many positions.
Both invite shortcuts: low-level cues that solve the pretext without understanding content. Jigsaw tiles can be ordered by matching edges or by colour fringes that lenses add near the borders. Authors cut tiles with random gaps and jitter colour channels for that reason. A shortcut solves the pretext and teaches nothing. Pretext features came close to supervised pretraining on some transfer tasks, but stayed well below it under a linear probe on ImageNet, and each task had to be designed by hand.
SimCLR and NT-Xent
Contrastive learning compares images instead of predicting a property of one. Two random augmentations of the same image are a positive pair; views of different images are negatives. Train so that a view is closer to its partner than to every other view in the batch. Features must keep what survives the augmentations — the content — and may discard what the augmentations change.
SimCLR is the simplest complete form. For every image of a batch it draws two augmentations , , runs both through a shared encoder to get , , then through a small projection head to get , . After training, is thrown away and is reused.
With images the batch has views. Let and . The NT-Xent loss for view , with partner index and temperature , is
Read it as classification: the logits are the similarities to the other views, divided by ; the class to predict is the partner. The gradient pulls the positive with force and pushes each negative with force — hard negatives that look similar get most of the push.
The head is discarded because the loss makes invariant to the augmentations, and that invariance destroys colour or orientation a downstream task may need. With a nonlinear head, a linear classifier on was more than ten points better than one on on ImageNet.
Temperature and batch size
The temperature sets how sharply the softmax distinguishes candidates. The ratio of gradients on two negatives with similarities and is
A small makes the hardest negatives dominate; a large spreads the gradient evenly. Neither extreme is good. With ResNet-50 and batches of , SimCLR’s linear-probe accuracy peaked near .
Batch size sets the number of negatives. If all similarities were equal, every would be and the loss would be — for . InfoNCE with candidates also bounds mutual information by , so the ceiling cannot exceed . Larger batches helped most when training was short; a batch of needs many accelerators.
Augmentations define what the features ignore. SimCLR’s decisive composition is random crop plus colour distortion: crops alone share a colour histogram, a shortcut that distortion removes. Contrastive learning wants stronger colour distortion than supervised training.
MoCo and learning without negatives
SimCLR draws negatives from the current batch, so more negatives need a bigger batch. MoCo keeps a queue of encoded keys from recent batches — by default — and compares the query with its own key and the queue by the same InfoNCE loss, using ordinary batches of .
Keys in the queue must stay comparable. MoCo encodes them with a separate encoder whose weights follow the query as a slow moving average,
and only is trained by backpropagation. With the key encoder averages roughly the last versions of the query.
Negatives prevent collapse: without them, “views of the same image should agree” is minimized by a constant encoder. BYOL drops negatives anyway and avoids collapse with an online predictor and a momentum target. SimSiam shows that even the momentum is unnecessary if one side has a predictor and the other a stop-gradient; removing the stop-gradient alone collapses accuracy to chance.
MAE and the linear probe
Masked image modelling returns to prediction of the image itself. The masked autoencoder (MAE) cuts an image into patches — using the Vision Transformer of the next topic — hides a random of them, encodes only the visible , and asks a small decoder to reconstruct the hidden pixels. The loss is MSE on the hidden patches only.
Images are redundant, so a small hole can be filled from neighbours; forces a model of objects and scenes, and the encoder processes a quarter of the patches, so pretraining is several times faster. MAE features excel after fine-tuning but score lower under a linear probe than contrastive features of the same network: one number does not rank methods.
The standard protocol is the linear probe: freeze the encoder, train only a linear classifier on . Fine-tuning, few-label probes and transfer to detection or segmentation complement it. A random untrained encoder and raw pixels are the floor; a probe that beats both shows that pretraining, not architecture alone, put the information there.
Digits, and what comes next
On the bundled digits, SimCLR trained without labels on training images, then a logistic regression on frozen features. With five labels per class the probe reached on SimCLR’s , against on raw pixels and on a random encoder. With all labels the gain shrank to about two points. Mild augmentations of tiny images left the head little to discard, so and were nearly tied — unlike the double-digit gap on ImageNet.
Self-supervised learning replaced hand-designed pretext tasks with contrastive and masked objectives. What it leaves open is the encoder that MAE needs: one that sees an image as a set of patches and can drop three quarters of them. A convolutional grid cannot do that. The next topic builds that encoder — the Vision Transformer.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.