Foundations to Frontier
Tests
E. Deep Learning › E16 Self-Supervised and Contrastive Learning

DINO / DINOv2

DINO (self-DIstillation with NO labels; Caron and colleagues, ICCV 2021) trains a student network to match the output distribution of a teacher network on different crops of the same image. The teacher is a momentum average of the student. Two simple operations on the teacher prevent collapse. Centring subtracts a running mean of its outputs, so no single dimension can win for every image. Sharpening applies a low temperature, so outputs cannot become uniform. With Vision Transformers, DINO's attention maps segment objects without supervision. DINOv2 (2023) scaled the recipe to curated data for general-purpose visual features. This page covers self-distillation, centring and sharpening, multi-crop and the two collapse modes. In the exercises you implement these operations, then train DINO and two ablations. Full DINO reached probe accuracy 0.75 with 13 of 32 output dimensions in use. Without centring, one dimension dominated (0.47). Without sharpening, the teacher's outputs became exactly uniform (0.25).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A student copying a slightly wiser teacher

DINO trains two copies of a network: a student and a teacher. The teacher is a slow average of the student. Both see different crops of the same image, and the student learns to give the same answer as the teacher. Left alone, this could go wrong in two ways: one answer could win for every image, or every answer could become equally likely. DINO adds two tweaks to the teacher, centring and sharpening, that block both failures. The demo shows how temperature controls sharpness.

Self-supervised learning lab
Probability on the positive (green): 0.571; InfoNCE loss 0.560. Low τ sharpens the softmax and focuses on the hardest negatives; high τ treats all negatives alike.
Why engineers care

DINO-trained Vision Transformers give features that locate objects without labels, and DINOv2 features work off the shelf for depth estimation, segmentation and retrieval, which is useful for robots and remote sensing.

📝 Quick check (Level 0)
0/3 answered
  1. 1. In DINO the teacher is…
  2. 2. Centring prevents…
  3. 3. Sharpening prevents…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Outputs: a K-dimensional head (K = 65,536 in DINO); P_s = softmax(g_s(x)/τ_s), P_t = softmax((g_t(x’) − c)/τ_t).
  • Loss: −Σ P_t log P_s over pairs of different crops, with the teacher’s output held fixed.
  • Teacher: θ_t ← mθ_t + (1 − m)θ_s, with m from 0.996 toward 1. The student sees all crops (2 global + several local); the teacher sees only the global ones.
  • Centring: c ← 0.9c + 0.1·(batch mean of the teacher’s outputs). Subtracting c stops one dimension being large for every image.
  • Sharpening: τ_t = 0.04 against τ_s = 0.1. With logits (1, 0), τ = 0.04 gives above 0.9999 on the first entry.
  • Collapse signatures:
    • uniform: the teacher’s entropy equals ln K (3.47 for K = 32);
    • one-dimension: the batch-average output uses about 1 dimension.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Entropy of a uniform distribution over 32 outputs:
  2. 2. Centre after one update from 1 toward 0 (m = 0.9):
  3. 3. Which crops does the teacher see?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

DINO in code

Exercise 1.

  • A very high teacher temperature gave uniform outputs and a low one gave sharp outputs.
  • Centring removed a dimension that won for every image.
  • The loss was 0 for matching sharp distributions, and the centre updated as an EMA.

Practice.

  • The official DINO and DINOv2 repositories provide ViT backbones. Typical settings: τ_t warmed from 0.04 to 0.07, τ_s = 0.1, centre momentum 0.9, teacher momentum 0.996 → 1, multi-crop with 2 × 224 and 10 × 96 crops.
  • Use DINOv2 features frozen with a linear head or k-NN for quick transfer.
  • Visualise the last-layer attention of the [CLS] token to see object masks.
t_out = [teacher(x) for x in global_crops]                       # no grad
s_out = [student(x) for x in global_crops + local_crops]
loss = 0
for i, t in enumerate(t_out):
    pt = F.softmax((t - center) / tau_t, dim=-1)                  # centre + sharpen
    for j, s in enumerate(s_out):
        if j != i: loss = loss - (pt * F.log_softmax(s / tau_s, dim=-1)).sum(-1).mean()
center = 0.9 * center + 0.1 * torch.cat(t_out).mean(0)
🐍 Exercise 1: centring and sharpening
Implement the teacher's centred, sharpened probabilities, the DINO loss and the centre update.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Typical teacher temperature:
  2. 2. DINO ViT attention maps show…
  3. 3. DINOv2 features are used…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Two opposite collapse modes.

  • Centring alone pushes toward uniform outputs, because subtracting the mean flattens the logits.
  • Sharpening alone pushes toward one dominant dimension, because a low temperature amplifies whatever is largest.
  • Applied together on the teacher, they balance: outputs stay confident per image (low entropy) but spread over many dimensions across images (high marginal entropy). That is exactly what makes the targets informative.

Self-distillation as clustering. With a K-way softmax head, DINO behaves like online clustering: each image is assigned confidently to some output “cluster,” and centring keeps clusters balanced. This is similar in spirit to SwAV’s equipartition, but achieved with a running mean instead of Sinkhorn.

Why ViTs. DINO’s training encourages the [CLS] token to attend to the object regions that are consistent across crops, so attention maps act as unsupervised segmentations, a property much weaker in supervised ViTs.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Centring alone leads toward…
  2. 2. Sharpening alone leads toward…
  3. 3. DINO resembles…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

What do centring and sharpening each prevent?

History.

  • M. Caron, H. Touvron, I. Misra, H. Jégou, J. Mairal, P. Bojanowski and A. Joulin, “Emerging properties in self-supervised Vision Transformers” (ICCV 2021).
  • M. Oquab et al., “DINOv2: learning robust visual features without supervision” (2023).

Exercise 2.

  • Setup: the same style-dominated world as before, with encoder 32 → 64 → 16, a head 16 → 32 → 32 outputs, an EMA teacher (m = 0.99), τ_s = 0.1 and 1500 steps.
  • Variants: full DINO (centring, τ_t = 0.04); without centring; and without sharpening (τ_t = 1.0).
  • Measurements: probe accuracy, the teacher’s mean per-image entropy, and the perplexity of its batch-average output (output dimensions used, of 32).
variant probe accuracy teacher entropy output dims used
raw observations 0.522 — —
DINO 0.750 0.88 12.95
no centring 0.472 0.05 1.60
no sharpening 0.246 3.47 32.0
  • Without centring, one dimension takes over: the teacher is extremely confident (entropy 0.05), but about the same dimension for every image (1.6 used). The targets carry almost no information.
  • Without sharpening, the teacher becomes uniform: entropy 3.47 = ln 32 exactly, so every target is the same flat distribution. The probe falls to 0.25, worse than raw.
  • With both, DINO learns: confident per-image outputs spread over about 13 dimensions, and probe accuracy 0.75.
  • Seeds: seeds 1 and 2 reproduced both collapse modes exactly (uniform entropy 3.47; one-dimension usage 1.0 and 1.6). Full DINO reached 0.74 and 0.57; the second seed learned less well, but still beat both ablations.
🐍 Exercise 2 (research): what do centring and sharpening each prevent?
Train DINO and ablations without centring and without sharpening, measuring probe accuracy, teacher entropy and output usage.

DINO in AI, robotics and aerospace

  • Foundation features: DINOv2 backbones for depth, segmentation and place recognition on robots and drones without task-specific pre-training.
  • Unsupervised object discovery: attention maps that highlight objects in aerial or inspection imagery.
  • Design lesson: when a method can collapse in two opposite directions, pair two opposite safeguards and check both diagnostics.

References

  1. M. Caron et al. (2021). “Emerging properties in self-supervised Vision Transformers.” Proc. ICCV.
  2. M. Oquab et al. (2023). “DINOv2: learning robust visual features without supervision.” arXiv:2304.07193.