Self-Supervised Learning (SSL): SimCLR, Masked Autoencoders (MAE) & DINO
How foundation models learn rich visual semantics from millions of UNLABELED images: Contrastive SimCLR, 75%-masked MAE ViT pre-training, and DINO's EMA Teacher-Student self-distillation!
Human labeling doesn't scale to 1 billion images or medical scans — Self-Supervised Learning (DINOv2, MAE, SimCLR) powers the strongest general-purpose vision backbones on Earth with ZERO human labels!
Knowing how DINOv2 and MAE work lets you pre-train custom domain foundation models on unlabeled satellite, pathology, or robotics video data.
DINOv2 embeddings work out-of-the-box for k-NN retrieval, depth estimation, and semantic segmentation even with a tiny linear head!
Modern Senior ML interview favorite: 'Compare SimCLR, MAE, and DINO — and how does DINO avoid representation collapse without negative pairs?'
Without negatives or anti-collapse tricks, how can a Student-Teacher SSL network trivially achieve 0.00 loss on every image?
- Explain why Self-Supervised Learning (SSL) unlocked foundation models by turning unlabeled data into free supervision
- Contrast the 3 dominant vision SSL paradigms: Contrastive (SimCLR), Masked Reconstruction (MAE), and Self-Distillation (DINO)
- Understand Representation Collapse (constant output vector) and how negatives (SimCLR) or Centering + EMA (DINO) prevent it
- Explain why MAE runs the ViT encoder on ONLY the 25% visible patches for a 4× pre-training speedup
4,096, each positive pair competes against 8,190 negatives!Self-Supervised Learning creates clever fill-in-the-blank games from raw data itself: 'Are these two cropped views from the same photo?' (SimCLR), 'Paint back the missing 75% of this picture!' (MAE), or 'Guess the whole scene from a tiny local peek!' (DINO)!
1. Contrastive SSL: SimCLR
SimCLR generates two strongly augmented views of every unlabeled image, passes them through a shared encoder + projection head, and minimizes InfoNCE / NT-Xent loss. Trade-off: requires very large batch sizes (or a momentum queue like MoCo) to supply enough hard negatives!
2. Generative Masking: Masked Autoencoders (MAE)
Because images have high spatial redundancy, MAE masks a massive 75% of image patches! Its asymmetric design feeds ONLY the 25% visible patches into the heavy ViT Encoder (4× faster + 4× less VRAM!), then uses a tiny Decoder to reconstruct missing pixels!
SimCLR vs. MAE vs. DINO Trade-Off Explorer
3. Self-Distillation: DINO & DINOv2
DINO eliminates negative pairs completely! A Student ViT (seeing small local crops) is trained to match the output distribution of an EMA Teacher ViT (seeing full global crops). Centering prevents one dimension from dominating, while Sharpening (low temperature) prevents uniform collapse — miraculously producing emergent object segmentation masks with ZERO labels!
Why is MAE pre-training ~4× faster than BERT-style masking on Vision Transformers?
The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.
No! You discard the SSL projection head / pixel decoder and attach a fresh task head directly onto the rich pretrained Encoder!
Masked Autoencoder (MAE) 75% Patch Reconstruction
Self-supervised pre-training learns deep visual semantics from millions of unlabeled images.
DINOv2 & Custom Domain Foundation Backbones
Powers zero-shot image retrieval, robotics 3D perception, pathology whole-slide imaging, and geospatial satellite analysis.
import torch
import torch.nn.functional as F
# 1. SimCLR NT-Xent Contrastive Loss for two augmented views (z1, z2)
def nt_xent_loss(z1: torch.Tensor, z2: torch.Tensor, temp: float = 0.2) -> torch.Tensor:
z1, z2 = F.normalize(z1, dim=-1), F.normalize(z2, dim=-1)
B = z1.size(0)
reps = torch.cat([z1, z2], dim=0) # [2B, D]
sim = (reps @ reps.T) / temp # [2B, 2B]
sim.fill_diagonal_(float("-inf")) # mask self-similarity
targets = torch.cat([torch.arange(B, 2 * B), torch.arange(B)])
return F.cross_entropy(sim, targets)
# 2. MAE Patch Masking (mask 75% of image patches before the encoder)
def random_patch_mask(patches: torch.Tensor, mask_ratio: float = 0.75):
B, N, D = patches.shape
keep = int(N * (1.0 - mask_ratio))
ids_shuffle = torch.rand(B, N).argsort(dim=1)
visible_ids = ids_shuffle[:, :keep]
visible = torch.gather(patches, 1, visible_ids.unsqueeze(-1).expand(-1, -1, D))
return visible, visible_ids
loss = nt_xent_loss(torch.randn(8, 64), torch.randn(8, 64))
vis, _ = random_patch_mask(torch.randn(2, 196, 128), mask_ratio=0.75)
print(f"NT-Xent loss: {loss.item():.3f} | MAE visible patches: {tuple(vis.shape)}")