AI Wiki中文/EN

DINO

DINO

Follow crop pairs, stopped teacher targets, centering and EMA; distinguish the DINO generations.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Start with the problem

A student looks at a close crop of an image; a teacher sees more of the same scene. They must agree on a probability vector, although neither has been given a class label. DINO turns this arrangement into self-supervised learning. Its name expands to self-distillation with no labels. The teacher follows an exponential moving average of the student rather than receiving gradients from the loss. Emerging Properties in Self-Supervised Vision Transformers — arXiv v2

The vector’s coordinates are learned output units, not a supplied list of animal species. Agreement only becomes useful if the output varies meaningfully across images. DINO combines a feature-wise teacher center, a sharper teacher distribution and multiple crops to manage this training problem.

We will calculate the original 2021 mechanism with three tiny vector crops, then place it beside DINOv2 and DINOv3. The later names refer to additional training and scaling work; changing a label on this small program does not reproduce those systems.

Definitions and derivation

Let ut,usu_t,u_s be teacher and student logits, cc a vector with one entry per output unit, and both temperatures positive. Only the teacher is centered:

pt=softmax⁡((ut−c)/τt),ps=softmax⁡(us/τs).p_t=\operatorname{softmax}((u_t-c)/\tau_t),\qquad p_s=\operatorname{softmax}(u_s/\tau_s).

There are two global crops and one local crop in our example. The teacher processes the globals; the student processes all three. Exclude matching global crops, leaving four ordered teacher–student crop pairs. Each contains the same three underlying examples. Average the cross-entropy across these pairs and examples; detach the teacher targets:

L=−1∣P∣N∑(g,v)∈P∑i,ksg⁡(pt,ikg)log⁡ps,ikv,∂Hi∂us,ik=ps,ik−pt,ikτs.L=-\frac1{|\mathcal P|N}\sum_{(g,v)\in\mathcal P}\sum_{i,k}\operatorname{sg}(p_{t,ik}^{g})\log p_{s,ik}^{v},\qquad \frac{\partial H_i}{\partial u_{s,ik}}=\frac{p_{s,ik}-p_{t,ik}}{\tau_s}.

The derivative shown is for one example before outer averaging. The code adds Xv⊤(ps−pt)/(Nτs)X_v^\top(p_s-p_t)/(N\tau_s) for each pair, then divides by four. After updating the student, update teacher parameters and the center. The center uses the old teacher’s raw logits, already computed on both global crops:

θt+=mθt+(1−m)θs+,c+=βc+(1−β)12N∑g=12∑iut,ig.\theta_t^+=m\theta_t+(1-m)\theta_s^+,\qquad c^+=\beta c+(1-\beta)\frac1{2N}\sum_{g=1}^{2}\sum_i u_{t,i}^{g}.

We set m=0.9m=0.9, β=0.8\beta=0.8, τs=0.5\tau_s=0.5 and τt=0.2\tau_t=0.2 for this calculation. These are teaching settings, not the original training schedule. Centering subtracts a different value from each output coordinate. Subtracting one scalar from a whole example’s row would leave softmax unchanged. Original DINO’s crop exclusions, detached targets and update order are documented in Section 3 and Algorithm 1. Emerging Properties in Self-Supervised Vision Transformers — arXiv v2

Computed teacher probabilities for the first global crop, sharing a 0–1 color scale. Output units are learned coordinates, not supplied semantic classes. Individual outputs sharpen in this small training run.
Computed teacher probabilities for the first global crop, sharing a 0–1 color scale. Output units are learned coordinates, not supplied semantic classes. Individual outputs sharpen in this small training run.

Run the calculation

The NumPy 1.26.4 program uses two-by-three linear weight matrices, not a Vision Transformer. With CPython 3.12.4, 150 steps at rate 0.03 reduce the moving-target objective from 0.749139160 to 0.121499467. Teacher outputs become sharp on individual examples while their batch mean remains near one third per unit. The mean entropy is about 0.012123172. These measurements describe this constructed batch; they establish neither semantic segmentation nor transfer accuracy. The teacher changes between steps, so the loss sequence is not optimization of one fixed target function.

import numpy as np


def views():return [np.array(x,dtype=float) for x in ([[1,.1],[.1,1],[-.9,-.7]],[[.9,-.1],[-.1,.9],[-.8,-.8]],[[.8,0],[0,.8],[-.7,-.5]])]


def softmax(x):
    z=x-x.max(axis=-1,keepdims=True);e=np.exp(z);return e/e.sum(axis=-1,keepdims=True)


def targets(teacher,center):return [softmax((x@teacher-center)/.2) for x in views()[:2]]


def objective(student,frozen_targets):
    crops=views();loss=0.;gradient=np.zeros_like(student);pairs=0
    for ti,target in enumerate(frozen_targets):
        for si,x in enumerate(crops):
            if ti==si:continue
            logits=x@student/.5;maximum=logits.max(axis=1,keepdims=True);logp=logits-maximum-np.log(np.exp(logits-maximum).sum(axis=1,keepdims=True));p=np.exp(logp);loss-=np.mean(np.sum(target*logp,axis=1));gradient+=x.T@(p-target)/(.5*len(x));pairs+=1
    return loss/pairs,gradient/pairs,pairs


def step(student,teacher,center,rate=.03):
    frozen=targets(teacher,center);loss,g,pairs=objective(student,frozen);raw_mean=np.concatenate([x@teacher for x in views()[:2]]).mean(axis=0)
    new_student=student-rate*g;new_teacher=.9*teacher+.1*new_student;new_center=.8*center+.2*raw_mean
    return new_student,new_teacher,new_center,loss


def initial():return np.array([[.4,-.2,.1],[-.1,.5,-.3]])


if __name__=='__main__':
    s=initial();t=s.copy();c=np.zeros(3);start=objective(s,targets(t,c))[0]
    for _ in range(150):s,t,c,loss=step(s,t,c)
    p=np.concatenate(targets(t,c));print('DINO-style loss before/after',round(start,9),round(objective(s,targets(t,c))[0],9),'center',c.round(9).tolist());print('teacher mean probabilities',p.mean(axis=0).round(9).tolist(),'mean entropy',round(float(-np.mean(np.sum(p*np.log(p),axis=1))),9))
    s=np.zeros((2,3));z=objective(s,targets(s,np.zeros(3)));print('uniform stationary loss',round(z[0],9),'gradient norm',float(np.linalg.norm(z[1])),'cross-view pairs',z[2])
DINO-style loss before/after 0.74913916 0.121499467 center [0.01975189, 0.066152346, -0.069237569]
teacher mean probabilities [0.333235839, 0.333127933, 0.333636228] mean entropy 0.012123172
uniform stationary loss 1.098612289 gradient norm 0.0 cross-view pairs 4

When the method fails

Centering and sharpening address different undesirable output patterns, but do not constitute a universal convergence proof. Set both weight matrices and the center to zero: every output is uniform, the loss is log⁡3\log 3 and the student gradient is exactly zero. Our program retains this counterexample rather than hiding it behind a random restart.

Crops can also remove the evidence needed to agree. If the local crop is only blank sky while the global view contains a bicycle, forcing exact instance information into both is an impossible demand. The augmentation policy determines which information gets rewarded.

Compute scales with the number of student crops and two teacher forwards. For a linear input dimension dd and KK output units, projection work is O(NdK)O(NdK) per crop; the real backbone adds its own cost. Teacher activations need no backward graph, but its parameters and forward pass still consume resources. A stop-gradient finite-difference check must hold teacher targets fixed; recomputing them through a perturbed student checks a different derivative.

Exercises with answers

  1. Why are there four crop pairs?

Answer 1: Each of two teacher globals can supervise the other global and the local crop: 2×2.

  1. What is the loss at uniform three-unit outputs?

Answer 2: Cross-entropy is log(3), approximately 1.098612289, with zero student gradient when targets are also uniform.

  1. Can subtracting the row mean implement the teacher center?

Answer 3: No. A row-constant shift cancels in softmax; DINO maintains a vector across output coordinates from batch statistics.

  1. Which teacher enters the center update?

Answer 4: The raw logits computed with the old teacher before the parameter update, averaged over its global crops.

Sources and next steps

Original DINO provides the self-distillation mechanism studied here. DINOv2 (2023) expands the recipe around curated image data, training stability and scale, including distillation into smaller models. Its “without supervision” refers to pretraining, not a promise that every downstream evaluation needs no labels. Emerging Properties in Self-Supervised Vision Transformers — arXiv v2; DINOv2: Learning Robust Visual Features without Supervision — arXiv v1

DINOv3’s first arXiv version was submitted on 2025-08-13, before this encyclopedia’s 2026-09-04 fact cutoff. The report introduces Gram anchoring to address deterioration of dense features during long training, alongside scaling and post-training work. Those are the report’s contributions; this chapter’s linear example does not implement them. DINOv3 — arXiv v1

Continue with BYOL to compare vector regression targets, and VICReg to study explicit variance/covariance regularization. When evaluating a DINO-family model, record its exact version, weights, crop policy, frozen or fine-tuned backbone and downstream labels.

Make a prediction, then check

Which operation changes the teacher probabilities?

Choose one answer

Learning objectives

  • Calculate multi-crop student gradients and the ordered EMA/center updates.
  • Separate a useful recipe from guarantees against collapse and from later versions.

Prerequisites & connections

Explore related knowledge →

References

  1. Emerging Properties in Self-Supervised Vision Transformers — arXiv v2
    Mathilde Caron; Hugo Touvron; Ishan Misra; Hervé Jégou; Julien Mairal; Piotr Bojanowski; Armand Joulin · 2021
  2. DINOv2: Learning Robust Visual Features without Supervision — arXiv v1
    Maxime Oquab et al. · 2023
  3. DINOv3 — arXiv v1
    Oriane Siméoni et al. · 2025

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-07 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.

  • Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, runnable examples and matching bilingual equations, code and exercises. Not an independent human or second-agent review.
  • Four focused CPython 3.12.4 tests passed per chapter: finite-difference gradients, sample covariance, teacher/center update order, hidden-input isolation, independent least squares, PSD projection, margin feasibility, tied-branch derivatives and transported factor actions as applicable, plus bilingual structure. All eight programs use NumPy 1.26.4; teaching calculations, not image benchmarks.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
  • Computed bilingual Matplotlib 3.9.1 charts bind both SVGs and numerical samples. Teacher probabilities, hidden-only reconstruction display and declared-basis Jacobians come from executed article functions; shared color scales and interpretation limits are explicit.
  • 2026-09-07 Linux CI portability check: run 34090622098 on Python 3.12.14 observed a 9.25185854e-18 residual at the uniform stationary point because exp(-log(3)) and 1/3 can differ by a final bit. Replaced bitwise-zero assertion with rtol=0, atol=8*float64 epsilon for bounded crops/temperature 0.5. Independent finite-difference and update-order tests remain unchanged; no article or algorithm edit, original frozen test retained.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.