DINOv2: Learning Robust Visual Features without Supervision
- Publication
- Transactions on Machine Learning Research 2024Journal
- First submitted to arXiv
- arXiv:2304.07193
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{contrastivelearningdinov22023,
title = {{DINOv2: Learning Robust Visual Features without Supervision}},
author = {Maxime Oquab and Timothée Darcet and Théo Moutakanni and Huy V. Vo and Marc Szafraniec and Vasil Khalidov and Pierre Fernandez and Daniel Haziza and Francisco Massa and Alaaeldin El-Nouby and Mahmoud Assran and Nicolas Ballas and Wojciech Galuba and Russell Howes and Po-Yao Huang and Shang-Wen Li and Ishan Misra and Michael Rabbat and Vasu Sharma and Gabriel Synnaeve and Hu Xu and Hervé Jégou and Julien Mairal and Patrick Labatut and Armand Joulin and Piotr Bojanowski},
year = {2023},
eprint = {2304.07193},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2304.07193}
}
We have already reviewed the first generation of DINO.
After two years, let’s see what improvements Meta AI Research has made on this architecture.
Problem Definition
In recent years, the mainstream development trend of visual models has become polarized:
On one hand, methods like CLIP and ALIGN learn through image-text alignment, using language as a semantic supervisory axis, successfully training foundational models with semantic understanding capabilities. These methods show strong performance in classification, retrieval, and multimodal tasks.
On the other hand, another route chooses not to rely on language, even rejecting external annotation for pretraining. This is a purer self-supervised perspective, letting images “speak for themselves,” enabling models to learn recognition, memory, abstraction, and generalization silently.
This route attempts to answer a more fundamental question:
In a world without language, can images still understand themselves?
This is the core pursuit of Self-Supervised Learning (SSL) techniques.
These methods can be roughly divided into two categories:
-
Intra-image pretext tasks, such as predicting masked patches, reconstructing original images, color restoration, or patch order prediction. These are similar in form to “fill-in-the-blank” tasks in language models, with typical examples including MAE and BEiT.
-
Discriminative self-supervision draws on contrastive learning, instance classification, or clustering. Representative methods include SimCLR, MoCo, BYOL, and DINO; they do not all use explicit negative pairs.
On standard datasets like ImageNet-1k, these methods have shown that frozen features can generalize, even approaching supervised training in some evaluations. Yet when scaling up model size, extending training, or using uncurated data, they can face unstable training and degraded features.
Perhaps the quality and diversity of data are even more critical factors?
Although self-supervised learning does not rely on manual annotation, it depends more heavily on the breadth and structural balance of the input data itself. When datasets suffer from topic shifts, long-tail imbalance, or excessive repetition, models tend to learn partial and hard-to-transfer representations.
Despite accumulating many impressive academic and industrial results, there remain several key unresolved issues for pushing these methods toward stable and usable visual foundational models:
- Can existing self-supervised techniques maintain sufficient stability and scalability when scaled up?
- Can learning without language or annotation during pretraining still produce general features useful for downstream applications?
- How can we effectively and automatically perform data filtering and distribution balancing when facing massive, uncurated image collections?
These questions remain open.
DINOv2 starts from the first generation’s foundation, further adjusting data strategies, enhancing architectural stability, and reconsidering the systematic design of self-supervised learning. If the data is better and the architecture more stable, perhaps we can go further—enabling models that do not rely on language to become a universal foundation for modern visual systems.
Data Collection
To enable the model to learn solid, generalizable visual features, data quality is the first priority.
When the goal is pretraining without labels, the responsibility of data selection no longer lies on target labels but on the diversity and representativeness of the images themselves. The curation pipeline does, however, start from existing datasets.
The data processing pipeline planned by the authors can be roughly divided into three steps, as illustrated below:
This is Figure 3 of the paper: images from both pools are embedded, duplicates are removed, and curated images guide retrieval from the web pool.
1. Preparing the Data Pool
The chosen target dataset LVD-142M consists of two parts:
- Curated portion: based on ImageNet-1k/22k, Google Landmarks, and multiple fine-grained datasets, serving as sources of “representative samples”;
- Uncurated portion: web images from a public crawl. The authors discard unsafe or restricted URLs, deduplicate, filter NSFW content, and blur identifiable faces, leaving about 1.2 billion candidate images before retrieval.
These uncurated images have not been manually selected by semantic class, but they have undergone the safety filtering and initial deduplication above.
2. Removing Duplicates
To avoid bias caused by duplicate training data, the authors introduced a specialized copy detection process to remove highly similar images, not only within the uncurated set but also excluding samples similar to test sets to prevent data leakage.
The implementation of this step builds on Pizzi et al. (2022), helping to keep the dataset diverse and clean.
3. Self-Supervised Retrieval
Here lies the truly ingenious design.
The authors first use a ViT-H/16 model previously self-supervised trained on ImageNet-22k to compute embedding representations for all images. Using cosine similarity as the distance metric, they retrieve uncurated images that “look like curated data.”
This retrieval is neither manual annotation nor keyword filtering but purely based on visual similarity of image features.
Next, the uncurated images are clustered by K-means. Depending on the scenario (large or small query datasets), for each base image, the top N nearest neighbors (N=4) or M images from the corresponding cluster are selected.
This choice balances data overlap and retrieval diversity.
Engineering Scale and Efficiency
Such large-scale data processing and retrieval require powerful computational resources.
The entire pipeline is built on the FAISS framework, using GPU-accelerated inverted indexing and quantization coding, distributed across 20 computing nodes each equipped with 8 V100 GPUs. It took less than two days to complete the cleaning and organization of 142 million high-quality training images.
Overall, DINOv2’s data preparation cleverly combines “existing high-quality datasets” with “visually similar web images,” using self-supervision to automatically select training samples and lay a foundation for what the model learns next.
Solution
The training strategy adopted by DINOv2 belongs to Discriminative Self-Supervised Learning. Overall, it can be seen as a hybrid design combining DINO and iBOT with SwAV’s centering mechanism, augmented by regularization terms and a high-resolution training strategy.
Image-Level Feature Alignment
This is Figure 2 from the original DINO paper, illustrating student, teacher, and EMA. DINOv2 later changes teacher normalization to Sinkhorn–Knopp; the predecessor diagram is not its complete architecture.
This part is based on the core idea of the DINO method, as illustrated above.
Using the DINO loss function, the goal is to ensure that the semantic representations of images under different views (augmentations), processed by the student and teacher networks respectively, remain consistent.
The specific procedure is as follows:
-
Take two different crops (called views) from the same image and input them separately into the student and teacher models;
-
Both models are Vision Transformers, and their class tokens are taken as the overall semantic vector representing the image;
-
The class tokens are then passed through separate MLP heads to produce vectors called “prototype scores.” The student uses softmax to obtain its prediction distribution, while the teacher obtains its target distribution through Sinkhorn–Knopp (SK):
-
DINOv2 uses SK to balance the teacher targets within a batch, replacing the moving-average centering used in DINO and iBOT. It does not simply smooth an already computed softmax output;
-
The final loss is the cross-entropy between the two distributions:
Here, the student is the training target, while the teacher is an exponential moving average (EMA) of the student weights and does not participate in backpropagation.
Patch-Level Prediction Task
This is Figure 3 from the iBOT paper. The MIM path at right shows prediction at masked patches. DINOv2 borrows this objective while changing the heads and teacher balancing.
To learn local details, the authors add iBOT's patch-level masked prediction objective:
-
Randomly mask certain patches in the student input, forming masked tokens;
-
These patches remain fully visible in the teacher input;
-
For each masked patch, the student predicts a distribution against the teacher's target from the corresponding visible patch. The student uses softmax and the teacher uses SK:
where is the index set of all masked patches. This task provides finer spatial-level supervision, aiding downstream pixel-level tasks such as segmentation.
Head Design
Both DINOv2 and iBOT require additional MLP projection heads to map transformer outputs into logits.
Although the original iBOT paper reports better results sharing the heads, DINOv2’s large-scale experiments found using two separate heads performs better, thus the two are fully decoupled.
Sinkhorn-Knopp Centering
To stabilize the teacher’s predicted distributions, DINOv2 adopts the Sinkhorn-Knopp normalization (SK) from SwAV to balance batch distributions.
This method iteratively normalizes rows and columns toward specified batch and prototype marginals. For a rectangular matrix, the rows and columns cannot each all sum to one. The implementation runs three normalization iterations.
Using SK reduces the risk of model collapse by preventing the output from concentrating on a single prototype.
KoLeo Regularization
DINOv2 introduces a rarely seen regularizer in this domain: KoLeo Regularizer (Kozachenko-Leonenko Regularizer), which encourages feature embeddings to be evenly and widely distributed in embedding space.
This term originates from differential entropy estimation and is formulated as:
where:
- is the nearest-neighbor distance for vector ;
- All vectors are normalized beforehand.
This regularization prevents features from over-concentrating during training, promoting coverage and diversity in feature representation.
High-Resolution Training Phase
Although high-resolution images are critical for tasks like segmentation and detection, directly using high resolution during pretraining is computationally expensive. Therefore, the authors adopt a compromise: briefly switch to 518×518 high-resolution images in the later pretraining phase to enhance detail signals.
The resolution ramp-up resembles UniViT and FlexiViT. The paper's smaller ablation compares 224 and 416 pixels; the final training recipe uses 518 pixels. A short high-resolution phase has a cost, but costs less than training at high resolution throughout.
DINOv2 combines image-level alignment, masked-patch prediction, balanced teacher targets, and KoLeo regularization. The ablations below show what each part contributes in the tested settings.
Engineering Implementation
The authors dedicate a chapter to introducing how to accelerate the training pipeline and reduce memory usage. Compared to iBOT, with the same hardware, DINOv2 achieves roughly 2× speedup and only 1/3 memory usage.
FlashAttention
Self-attention layers are the biggest computational bottleneck in ViT architectures.
The team developed an optimized FlashAttention implementation that outperforms the original in both memory and speed, and supports more hardware platforms and architectural variants.
They found that aligning embedding dimensions with GPU-friendly sizes (e.g., 64 per head, total embedding multiple of 256) further improves efficiency.
Therefore, ViT-g uses 1536 dimensions and 24 heads (64 dims per head), replacing the commonly used 1408 dims / 16 heads design.
Experiments show comparable accuracy with better efficiency.
Sequence Packing
ViT inputs are patch tokens, and DINO-style methods process two crops simultaneously:
- Large crops (resolution 224) produce long sequences;
- Small crops (resolution 98) produce short sequences.
Previous approaches forwarded these separately, causing batch size inconsistency and wasted computation.
DINOv2 introduces a technique from NLP: Sequence Packing.
Multiple token sequences of varying lengths are concatenated into one long sequence, and a block-diagonal attention mask prevents cross-attention between different sequences. This yields the same effect as separate forwards but significantly improves computational efficiency.
This design relies on low-level support and is implemented on top of the xFormers library.
Stochastic Depth
Stochastic Depth is a form of regularization that randomly skips the residual branch for some samples during training.
Traditionally, the residual branch is computed before its output is masked for dropped samples. DINOv2 instead skips that residual computation while retaining the shortcut, saving memory and compute.
This requires a special kernel that randomly permutes samples in the batch dimension and only computes the first samples for the affected branch. At the paper's drop rate, roughly 40% of the samples skip that branch on each layer; this is not a 40% reduction in total training cost.
Distributed Training
Training billion-scale models (e.g., ViT-g with ~1.1B parameters) is bottlenecked by memory.
DINOv2 employs Fully-Sharded Data Parallel (FSDP) to shard model replicas across GPUs, including:
- Student network,
- Teacher network,
- Optimizer first- and second-moment parameters (AdamW).
Four float32 copies of a billion parameters occupy about 16 GB, before gradients, activations, and temporary buffers. At 1.1 billion parameters the four copies alone are about 17.6 GB. FSDP shards them across GPUs rather than requiring all copies on one device.
The backbone communicates weights and gradients in float16, while MLP-head gradients are reduced in float32 for stability. The paper reports about 50% less communication than its float32 DDP comparison; the gain depends on the setup.
In the authors' measured configurations, PyTorch FSDP with mixed precision was generally faster than DDP with autocast.
Model Distillation
After training large models like ViT-g, DINOv2 does not directly train smaller models like ViT-B or ViT-L from scratch. Instead, knowledge distillation is used to let smaller models mimic the large one’s outputs.
The training strategy reuses the teacher-student framework with these modifications:
- The pretrained ViT-g is frozen as teacher;
- Masking and stochastic depth are disabled to simplify training;
- The iBOT loss is applied to two global crops;
- The student’s EMA is kept as the final model output.
This design is similar to Duval et al.’s method but without changing the loss function structure, reusing the original pipeline for simplicity and practicality.
Experiments show that even ViT-L distilled this way outperforms training from scratch significantly.
Ablation Experiments
To verify the effectiveness of each component design, the authors conducted several experiments covering training strategies, data sources, model sizes, loss components, and resolutions.
Model Training Process
Using iBOT as the baseline, the authors sequentially added various DINOv2 techniques (such as dual heads, Sinkhorn centering, and KoLeo regularization) and observed performance on ImageNet-1k with k-NN and linear-probe evaluations.
The results in Table 1 of the paper come from a ViT-L trained on ImageNet-22k. Most steps improve at least one evaluation, but the components are added sequentially, so each row is not an independent ablation. Adding LayerScale and stochastic depth together lowers linear-probe accuracy from 83.2 to 82.0; the authors say these changes help prevent NaN loss during training. Untying the heads at the end raises k-NN from 81.7 to 82.0, while linear-probe accuracy falls from 84.7 to 84.5. Sinkhorn–Knopp leaves both scores unchanged at that step.
Pretraining Data
To test the impact of data quality on features, the authors compared three datasets:
- LVD-142M (curated set selected via visual retrieval)
- ImageNet-22k (traditional large-scale labeled dataset)
- Uncurated-142M (random samples from the same source web data)
All three were trained with ViT-g/14 for the same number of iterations, below the final training run and without high-resolution adaptation.
The image reproduces Table 2 of the paper. The uncurated row randomly samples 142 million images from the same web pool. Compare both the ImageNet-1k and transfer columns:
- LVD-142M outperforms random uncurated samples on most measures, though ADE-20k is an exception (47.7 versus 48.5 mIoU);
- LVD-142M surpasses ImageNet-22k on most benchmarks except ImageNet-1k;
- On domains not used as references for curation (such as iNaturalist and Places205), LVD-142M also scores higher than ImageNet-22k.
LVD-142M scores 85.8 on ImageNet-1k, just below ImageNet-22k's 85.9. This experiment shows that data curation remains an important design choice even for self-supervised learning.
Importance of Loss Components
These are Table 3(a) and 3(b) of the paper. The left table includes Oxford-M mAP, and the right includes ADE-20k mIoU. Each model uses the same iteration count, shorter than the final training run.
Next, the authors evaluated the actual contribution of each loss term via ablation on:
-
KoLeo Regularization
On Oxford-M retrieval, adding KoLeo raises mAP from 55.6 to 63.9, a gain of 8.3 percentage points. ImageNet-1k classification also rises by 0.5 points, while ADE-20k falls slightly from 47.2 to 47.1 mIoU.
This shows the regularizer successfully encourages feature dispersion, especially benefiting retrieval tasks requiring detailed feature discrimination.
-
iBOT-style Masked Image Modeling
Removing this loss changes ADE-20k mIoU from 47.1 to 44.2, a drop of 2.9 points. This supports the value of patch-level supervision for the tested segmentation setup.
Knowledge Distillation Effect
To reduce training costs of smaller models, DINOv2 uses ViT-g as a frozen teacher to distill ViT-L/14 and compares it against training from scratch.
In Figure 5 of the paper, the left panel compares 12 benchmarks and the right panel summarizes eight task groups. Distilled ViT-L/14 beats the from-scratch counterpart on all 12 in this experiment; the result is specific to these models and training conditions.
High-Resolution Training
Finally, the authors tested whether high-resolution training from scratch is necessary:
- Using ViT-L/16 on ImageNet-1k, compared fixed resolutions of 224 and 416 against 224 followed by 10k more iterations at 416;
- Evaluation metrics included ImageNet classification and ADE segmentation;
- Training entirely at 416 gives the best results at most evaluation resolutions shown, but costs about three times as much computation as training entirely at 224; switching to 416 only for the last 10k iterations yields a similar curve while paying the extra high-resolution cost only for that final phase.
Figure 6 of the paper shows the 224 run in orange, the full 416 run in pink, and the short 224→416 run in blue. Its horizontal axis is evaluation resolution; the panels report ImageNet-1k accuracy and ADE-20k mIoU. The final DINOv2 recipe uses a 518-pixel high-resolution phase, distinct from this 416-pixel ablation.
Discussion
ImageNet Classification
Table 4 in DINOv2 trains a linear classifier over frozen backbones. Architectures and pretraining datasets differ across rows, so this is not a matched-size comparison.
In the ImageNet-1k linear classification task, DINOv2 demonstrates extremely strong feature representation capability.
With a frozen backbone and a trained linear classifier, ViT-g/14 reaches 86.5% Top-1 on ImageNet-1k validation, 4.2 percentage points above the best earlier self-supervised model in the table, iBOT at 82.3%. It also slightly exceeds OpenCLIP ViT-G/14 at 86.2% and EVA-CLIP ViT-g/14 at 86.4%. These rows differ in architecture and pretraining data, so the gaps cannot all be attributed to the training method.
Without text supervision during pretraining, DINOv2 ViT-g/14 also scores 89.6% on ImageNet-ReaL and 78.4% on ImageNet-V2; the table lists 83.5% in k-NN evaluation. These are classification results from the same evaluation suite.
Across DINOv2 ViT-S/B/L/g, the table's linear classification accuracies are 81.1%, 84.5%, 86.3%, and 86.5%. The progression shows how these pretrained models perform as size grows; the table does not control every cost difference between architectures.
This table supports DINOv2's strong ImageNet linear evaluation, approaching or slightly exceeding the listed weakly supervised models. Its transfer to other tasks must still be judged by the downstream experiments below.
Video Classification
Table 7 in DINOv2 uses frozen features and trained linear classifiers. It covers iNaturalist, Places205, and three video datasets; the next image is a separate table of 12 image benchmarks.
On additional image and video classification tasks, DINOv2's representations transfer across visual domains and from images to video. The paper evaluates iNaturalist, Places205, and the 12 image tasks used by SimCLR.
DINOv2 ViT-g/14 scores 81.6% and 85.7% on iNaturalist 2018 and 2021, ahead of OpenCLIP ViT-G/14 at 73.0% and 76.0%. On Places205, however, DINOv2's 67.5% trails OpenCLIP's 69.8%.
For video classification, despite seeing no video during pretraining, the authors extract eight evenly spaced frames. They average frame features for K400 and UCF-101, concatenate them for SSv2, then train a linear classifier. DINOv2 ViT-g/14 scores 78.4%, 91.2%, and 38.3% on those three datasets, versus OpenCLIP's 78.3%, 90.7%, and 35.8%. The SSv2 gap is 2.5 percentage points.
Table 8 in DINOv2 covers twelve object, scene, and texture benchmarks.
Finally, across these twelve image classification tasks, DINOv2 ViT-g/14 averages 92.1%, close to OpenCLIP ViT-G/14 at 91.9%. DINOv2 leads on Aircraft, 87.2% to 80.2%, but trails on Cars, 91.4% to 96.1%, and SUN, 78.7% to 84.0%. The models have different strengths across datasets.
Instance Recognition
Table 9 in DINOv2 evaluates non-parametric retrieval with frozen features, with separate Oxford/Paris M and H difficulty settings and multiple Met metrics.
In instance-level recognition tasks, DINOv2 also exhibits strong discriminative ability.
Using non-parametric retrieval ranking by cosine similarity between query and database images, the comparison includes both self- and weakly supervised models.
Across landmarks (Oxford and Paris), artwork retrieval (Met), and historical street views (AmsterTime), DINOv2 shows strong results. ViT-L/14 reaches 54.0 mAP on Oxford-Hard, above the listed iBOT at 12.7 and OpenCLIP at 19.7; it scores 83.5 on Paris-Hard and 50.0 on AmsterTime. ViT-g/14 is not highest in every column: its Oxford-Hard score of 52.3 is below ViT-L/14.
Together with the category classification results, these retrieval scores show useful frozen features across task granularities. The table does not directly test the mechanism by which the model recognizes small differences.
Semantic Segmentation
Table 10 in DINOv2 distinguishes lin. from +ms evaluation. The parenthesized numbers in the headers are reference results from other methods, not DINOv2 scores.
In dense tasks such as semantic segmentation and monocular depth estimation, the authors freeze the backbone and train downstream predictors to examine its patch-level features.
For semantic segmentation, “lin.” uses a linear layer to predict low-resolution logits from patch tokens and then upsamples them. The “+ms” setting concatenates features from the last four layers, uses higher input resolution, and evaluates at multiple scales. DINOv2 ViT-g/14 reaches 53.0 mIoU on ADE-20k in the +ms setting, near the cited fully fine-tuned MAE + UperNet result of 53.6. On Pascal VOC it scores 86.2, still below the listed best result of 89.0.
The authors also insert a frozen ViT-g/14 backbone into ViT-Adapter + Mask2Former. The adapter and head are still trained, with about 66% of the weights frozen. This setting reaches 60.2 mIoU on ADE-20k, near the cited 62.9.
Qualitative Results
Beyond quantitative evaluation, the authors show segmentation, depth prediction, and feature visualizations so that we can inspect the model's output.
First, visual comparisons of semantic segmentation and depth estimation:
Figure 7 in DINOv2 compares frozen features with linear predictors on ADE20K, NYUd, SUN RGB-D, and KITTI. Compare Input, OpenCLIP-G, and DINOv2-g within each group.
In the ADE20K examples, with a frozen backbone and a linear predictor, DINOv2's connected regions and object boundaries look more complete than OpenCLIP's. These are qualitative examples; the overall comparison rests on the mIoU table above.
The depth examples also look smoother and less noisy. A chair in the SUN RGB-D example, for instance, has a clearer position in the DINOv2 prediction. This is depth estimation, not chair-class recognition.
Next, the paper applies the trained linear segmentation and depth predictors to paintings, sketches, and images in different styles:
Figure 8 in DINOv2 includes paintings and animals. Out of distribution refers to the downstream predictors.
The predictions still show parts of the object outlines and depth structure, offering qualitative examples of transfer across image styles.
Finally, analysis of feature space structure is presented:
Figure 9 in DINOv2 first separates the main object and background by the sign of the first principal component. The authors then perform a second PCA on the retained patch features and map its first three components to RGB colors.
Similar parts of related images often show similar colors. That is an interesting structure the authors observe in the features; the PCA visualization itself is not a quantitative test of part recognition.
Conclusion
From an engineering practitioner’s perspective, DINOv2’s greatest value lies in delivering “high-quality, versatile visual features that can be directly applied to multiple tasks without fine-tuning.”
This means we can use fewer resources and simpler downstream modules for tasks that once called for full-backbone fine-tuning. Whether classification, segmentation, depth estimation, or instance retrieval, DINOv2 offers frozen features that can be paired with a relatively simple head. That head may still need labeled training, and a deployment decision requires evaluation on the target domain.
Moreover, DINOv2 shows robust cross-domain performance and a sense for structural detail, making it a promising backbone for tasks with limited data, substantial variation, and demanding semantic distinctions.
More importantly, it need not remain a complete black box. Through PCA and patch matching, we can inspect some of the semantic structure and object parts encoded in the features. These views can help with error analysis, though they do not explain every prediction.
If you work on medical images, satellite imagery, retail product recognition, or even autonomous vehicle perception, DINOv2 may be a general-purpose foundation worth considering—and testing on your own data.