Interactive Explainer
Vision Pretraining, Without Labels
Pull two augmentations of the same image together, push everything else apart. Or mask 75% of an image and predict the rest. Two label-free recipes that pretrain every modern vision backbone. Below: a live contrastive lab where you augment an image, watch its embedding barely move, and read the InfoNCE loss straight off a similarity matrix — plus a mask-and-reconstruct MAE demo.
Why we don't train from scratch any more
ImageNet has 1.2M labelled images. A typical applied vision task has, optimistically, a few thousand labelled examples. A ViT-Base trained from scratch on that would overfit catastrophically. Self-supervised pretraining on the much larger pool of unlabelled images (millions, easy to scrape; billions, with a bit of ingenuity) gets you a backbone that needs only a thin fine-tune on labels.
Every recipe here invents a pretext task: a supervised-looking objective whose labels come free from the image itself. Two big families dominate. Contrastive methods (SimCLR, MoCo, CLIP) make representations of two views of one image agree while disagreeing with other images. Generative methods (MAE, BEiT) hide part of the image and reconstruct it. We'll build a live demo of each.
Contrastive learning & the InfoNCE loss
Take an image, make two randomly augmented views of it (crop, flip, colour-jitter, blur). Push both through an encoder to get embeddings $z_i$ and $z_j$. These two views came from the same image, so they form a positive pair and their embeddings should be close. Every other image in the batch is a negative, and should sit far away. The InfoNCE loss makes that a softmax classification — "which of the $2N$ views is my positive?":
$\operatorname{sim}(a,b)=\tfrac{a\cdot b}{\lVert a\rVert\,\lVert b\rVert}$ is cosine similarity and $\tau$ is a temperature (smaller = harder negatives, sharper contrast). The numerator pulls the positive pair together; the denominator pushes against every negative in the batch — which is why SimCLR needs large batches (~4k–8k) to see enough negatives, and why MoCo swaps the batch negatives for a momentum-updated queue.
Augmentations are the whole inductive bias: the network is forced to produce the same embedding for both views, so it learns features invariant to whatever you augmented over. Random crop + colour jitter + Gaussian blur is the standard recipe; dropping any one costs 5–10 ImageNet linear-probe points.
The MAE recipe — mask and reconstruct
Masked autoencoders (He et al., 2022) are the simplest generative recipe that works at scale. Divide the image into patches, randomly mask a large fraction (75% is the headline number), feed only the visible patches into a ViT encoder, and ask a small decoder to reconstruct the masked patches. The loss is mean-squared error in pixel space, computed only on the masked patches:
The asymmetry — an encoder that sees only 25% of the patches, a decoder that sees the full set with placeholders for the masked ones — is what makes this fast. Pretraining on ImageNet-1k takes under a day on 8 GPUs. Drag the mask ratio and watch reconstruction quality degrade as fewer patches survive:
DINO & self-distillation without labels
DINO (Caron et al., 2021) and DINOv2 (Oquab et al., 2023) are the most-used non-contrastive recipe. A student network must match the predictions of a teacher network on a different view of the same image; the teacher is an exponential moving average of the student:
The trick is preventing collapse — both networks predicting a constant. Two stabilisers:
- Centering. Subtract a running mean $c$ from the teacher's output before softmax. Removes the easy "always predict the same vector" attractor.
- Sharpening. Teacher temperature $\tau_t \ll \tau_s$. The teacher's distribution is sharper than the student's, forcing the student to commit to a confident prediction.
DINOv2 added Sinkhorn-Knopp centering, iBOT-style patch-level loss (the student must also match the teacher on masked patches), and curated pretraining data. The resulting features are spatially well-organised, which is why DINOv2 is the current default for any downstream segmentation or detection task.
JEPA — predict features, not pixels
MAE spends capacity predicting pixels: the loss in pixel space punishes you for getting fine textures wrong, which doesn't help downstream semantics. Joint Embedding Predictive Architectures (I-JEPA, V-JEPA; LeCun et al., 2022–24) sidestep this by predicting in feature space:
Both context and target pass through the (same) encoder $f$. A small predictor $g$ predicts the feature embedding of the target from the context's embedding plus a target location code $\ell_{\text{target}}$; $\operatorname{sg}[\cdot]$ is a stop-gradient. By skipping pixel prediction, JEPA spends its parameters on representations useful for downstream tasks, and is increasingly competitive on linear-probe benchmarks at a fraction of MAE's compute.
The four families of SSL recipes
| Family | Pretext | Examples | What it learns well | What it struggles with |
|---|---|---|---|---|
| Contrastive | Pull augmentations of same image together; push others apart | SimCLR, MoCo, CLIP | Discriminative features, transfer to classification | Needs huge batches; weak on dense tasks |
| Distillation | Match a teacher (often EMA of student) on different views | DINO, DINOv2, iBOT | Strong dense features; SOTA for downstream segmentation | Stable training is delicate (centering, sharpening) |
| Generative | Reconstruct masked pixels / tokens | MAE, SimMIM, BEiT | Sample efficiency; works on any modality | Linear-probe accuracy lower than DINO/CLIP |
| Predictive | Predict features of masked regions, not pixels | I-JEPA, V-JEPA, V-JEPA 2 | Very efficient; emphasis on semantic features | Newer; tooling and recipes still maturing |
A useful rule of thumb: for classification-flavoured tasks and small labelled fine-tune sets, prefer DINOv2 or CLIP. For dense prediction, segmentation, or any task where spatial detail matters, prefer DINOv2 or MAE. For unusual modalities (thermal, satellite, hyperspectral) MAE is the easiest to retrofit.
Why this matters: linear-probe efficiency
The cleanest way to evaluate pretraining is to freeze the backbone and train a single linear head on a small labelled set. The slope of that "labelled-data vs accuracy" curve is the SSL value. Below: a synthetic curve contrasting random init with SSL pretrained as you grow the labelled fraction.
The augmentation-as-prior view
The single biggest knob in any non-generative SSL recipe is the augmentation set, for the reason the contrastive lab above made tangible: the loss forces the same representation for two augmented views, so the network learns features invariant to whatever you augmented over. Whatever you don't augment is what the model is free to latch onto.
- Random crop. Locality + scale invariance. Removing it tanks ImageNet linear probe by ~25 points.
- Colour jitter. Colour-invariance. Crucial for natural images where colour is unreliable.
- Gaussian blur. Texture-invariance. Helps especially when the target task cares about shape, not texture.
- Solarisation / random greyscale. Used in DINO; further weakens colour as a shortcut.
- What to not augment. If your downstream task cares about a property (rotation in medical scans, exact pixel intensity in remote sensing), don't augment it away — the model will learn to ignore exactly the thing you need.
Practical recipes
- Custom-modality pretraining. If your domain (thermal, medical, satellite, hyperspectral, microscopy) is unlike ImageNet, an off-the-shelf backbone helps less. Pretrain MAE on tens to hundreds of thousands of in-domain unlabelled images; fine-tune on the few hundred labels you actually have.
- Continual pretraining of a public backbone. Cheaper: start from DINOv2 or CLIP weights, run a short MAE-style continual pretrain on your in-domain data, then fine-tune. You get both the big-pretrain generality and the modality alignment.
- Linear probe before fine-tune. Always evaluate the frozen backbone with a single linear head first. If the linear probe is bad, fine-tuning rarely saves it.
- Vision-language alignment. CLIP-style training on (image, caption) pairs gives you zero-shot classification and free-text retrieval. The captions don't need to be high quality — Web noise is enough.
- Don't reinvent. Public DINOv2, CLIP, and SAM backbones cover most "I need a strong vision encoder" needs in 2026. Pretrain from scratch only when no public backbone lives in your domain.
Reading list
- Chen, Kornblith, Norouzi, Hinton (2020) — SimCLR. The contrastive lab above.
- He et al. (2020) — MoCo. Momentum queue of negatives.
- Caron et al. (2021) — DINO.
- He, Chen, Xie, Li, Dollár, Girshick (2022) — Masked Autoencoders Are Scalable Vision Learners (MAE).
- Assran et al. (2023) — I-JEPA.
- Oquab et al. (2023) — DINOv2. The currently dominant SSL backbone.
- Bardes et al. (2024) — V-JEPA. Video extension.