DINO: Self-Supervised Vision Transformers for Feature Extraction

Jul 7, 2025

Introduction

Training high-performance computer vision models typically requires massive, manually labeled datasets, which are expensive and time-consuming to produce. DINO (Self-Distillation with No Labels) is a self-supervised learning framework developed by Facebook Research that eliminates this bottleneck by allowing Vision Transformers (ViTs) to learn rich visual representations directly from unlabeled images. With over 7.6k GitHub stars, DINO provides a way to extract semantically meaningful features that often surpass supervised counterparts in tasks like image clustering and segmentation.

What Is DINO?

DINO is a self-supervised learning method that uses a student-teacher distillation process to train Vision Transformers (ViTs) without any labels. It is implemented in PyTorch and released under the Apache License 2.0. The framework allows a model to learn the essence of an image by matching the output of a student network to a teacher network, both of which are ViTs, using different augmented views of the same image.

The project’s primary goal is to discover “emergent properties” of ViTs, such as the ability to automatically capture object boundaries and scene layouts without being told what an object is. This makes DINO a powerful foundation for downstream computer vision tasks where labeled data is scarce.

Why DINO Matters

Before DINO, most self-supervised learning (SSL) methods relied on contrastive learning, which requires a large number of “negative samples” (images that are different from the target) to prevent the model from collapsing into a single output. DINO removes the need for negative samples entirely, simplifying the training pipeline and reducing the computational overhead associated with managing large memory banks or massive batch sizes.

The significance of DINO lies in its ability to produce features that are inherently more semantic. While supervised models often focus on the specific labels they were trained on, DINO’s self-distillation process encourages the model to learn the global structure of the image. This results in features that are exceptionally good for k-Nearest Neighbor (k-NN) classification and semantic segmentation, often performing better than supervised ViTs on these specific tasks.

As the foundation for later versions like DINOv2 and DINOv3, the original DINO project established the core principles of self-distillation for vision, proving that transformers can learn a high-level understanding of the world without human intervention.

Key Features

  • Self-Distillation Framework: DINO uses a student-teacher architecture where the student learns to predict the teacher’s output. This avoids the need for contrastive pairs or negative samples, making the training process more efficient.
  • Multi-Crop Augmentation: The model uses a strategy of global and local crops of an image. The student sees local crops, while the teacher sees global crops, forcing the model to learn that a small part of an image represents the same object as the whole image.
  • Centering and Sharpening: To prevent the model from collapsing (outputting the same value for every image), DINO implements a centering and sharpening mechanism that stabilizes the teacher’s output distribution.
  • Emergent Semantic Segmentation: One of the most striking features is that DINO-trained ViTs automatically learn to segment objects. The self-attention maps of the [CLS] token in the last layer explicitly contain object boundaries.
  • High-Performance k-NN Classification: Because the learned features are so discriminative, DINO models can perform image classification using a simple k-NN classifier without any further training or fine-tuning.
  • Pretrained Model Suite: The repository provides a variety of pretrained weights for different ViT sizes (e.g., ViT-S, ViT-B), allowing developers to jumpstart their projects without training from scratch.

How DINO Compares

Feature DINO SimCLR MoCo v3
Negative Samples Required No Yes Yes
Primary Architecture Vision Transformer (ViT) ResNet / ViT ViT
Training Objective Self-Distillation Contrastive Learning Contrastive Learning
Semantic Segmentation Emergent (Automatic) Requires Fine-tuning Requires Fine-tuning

DINO differs from contrastive frameworks like SimCLR and MoCo by removing the need for negative samples. While SimCLR requires massive batch sizes to find enough negatives, DINO’s student-teacher distillation process is more stable and produces features that are more naturally aligned with the semantic structure of an image. This makes DINO particularly superior for tasks that require a dense understanding of the image, such as segmentation or object retrieval.

However, a tradeoff is that DINO’s training can be sensitive to the centering and sharpening hyperparameters. If these are not tuned correctly, the model can collapse. Contrastive methods are generally more robust to this specific type of failure, but they are more computationally expensive to manage at scale.

Getting Started: Installation

DINO is built on PyTorch. To get started, you will need a Linux environment and a GPU with CUDA support for efficient training and inference.

Prerequisites

Ensure you have PyTorch and torchvision installed. You can install them via pip:

pip install torch torchvision

Cloning the Repository

Clone the official DINO repository from GitHub:

git clone https://github.com/facebookresearch/dino.git

Installing Dependencies

Navigate to the project directory and install the required packages listed in the requirements file:

cd dino
pip install -r requirements.txt

How to Use DINO

The simplest way to start using DINO is by leveraging the pretrained models available via PyTorch Hub. This allows you to extract features from images without needing to download weights manually or set up a complex training pipeline.

The basic workflow involves loading the model, preprocessing your image into a tensor, and passing it through the model to get a feature vector (embedding). This embedding can then be used for similarity search, clustering, or as input to a lightweight classifier.

If you are training a model from scratch, you can use the provided training scripts. The process involves specifying the architecture (e.g., vit_small) and the path to your unlabeled dataset (e.g., ImageNet).

Code Examples

Loading a Pretrained Model via PyTorch Hub

This example shows how to load a DINO ViT-S/16 model and extract a global image embedding.

import torch

# Load the DINO ViT-S/16 model from PyTorch Hub
model = torch.hub.load('facebookresearch/dino:main', 'dino_vits16')
model.eval()

# Example input tensor (batch size 1, 3 channels, 224x224 pixels)
# In a real scenario, use torchvision.transforms to preprocess your images
img = torch.randn(1, 3, 224, 224)

with torch.no_grad():
    embedding = model(img)

print(f"Feature vector size: {embedding.shape}")

Training a DINO Model

To train a model using the provided CLI, run the following command. This specifies the architecture and the data path for the unlabeled training set.

python main_dino.py --arch vit_small --data_path /path/to/imagenet/train --output_dir /path/to/saving_dir

Evaluating Performance with k-NN

To evaluate the quality of the learned features using a k-Nearest Neighbor classifier on ImageNet, run:

python eval_knn.py --data_path /path/to/imagenet

Real-World Use Cases

DINO’s ability to learn features without labels makes it an ideal choice for domains where data annotation is prohibitively expensive.

  • Satellite Imagery Analysis: Organizations like the World Resources Institute (WRI) use DINO to measure tree canopy heights from satellite images. Because satellite data is vast and unlabeled, DINO can learn the general structure of forest cover without needing thousands of manually labeled canopy maps.
  • Space Robotics: NASA JPL integrates DINO into Mars exploration robots. This allows the robots to perform multiple vision tasks, such as terrain mapping and object recognition, using a single frozen backbone, which minimizes the compute resources required on the robot’s hardware.
  • Image Retrieval Systems: Because DINO features are highly discriminative, they are used to build efficient “search by image” backends. By indexing the [CLS] embeddings of a large image library, a system can find visually similar images using simple cosine similarity search.
  • Unsupervised Object Discovery: Researchers use DINO to discover new object categories in unlabeled datasets. By clustering the embeddings, the model can group similar objects together, revealing the semantic categories present in the data without any human-provided labels.

Contributing to DINO

The DINO repository is currently archived by the owner, meaning it is in read-only mode. However, you can still report issues or suggest improvements through GitHub’s standard flow. If you are looking to contribute to the active development of self-supervised vision, you are encouraged to explore the DINOv2 and DINOv3 repositories, which are the successors to this project.

The project follows the Apache License 2.0, allowing you to fork the repository and implement your own improvements or extensions to the original DINO framework.

Community and Support

DINO was developed by Meta AI (formerly Facebook AI Research – FAIR). la is a foundational project that has influenced a wide range of of the community. Support is primarily provided through the original GitHub repository’s Issues section, although the repository is now archived. For active discussions on the latest iterations of the DINO family, the Meta AI blog and the DINOv2 GitHub repository are the primary official channels.

The community size is significant, as evidenced by the thousands of stars and forks of the original repository, which has become a la benchmark for self-supervised learning in vision transformers.

Conclusion

DINO is a transformative approach to self-supervised learning that proves Vision Transformers can learn a high-level understanding of the world without human labels. By removing the need for negative samples and using a student-teacher distillation process, DINO provides a feature extractor that is more semantic and naturally aligned with the image’s structure.

For developers and researchers, DINO is the right choice when you have a massive amount of unlabeled data and want a powerful, frozen backbone for downstream tasks like segmentation or retrieval. It is not the right choice if you need a model that is extremely lightweight for real-time mobile deployment without any distillation process.

Star the repo, try the quickstart via PyTorch Hub, and explore the emergent properties of your own unlabeled datasets.

What is DINO and what problem does it solve?

DINO is a self-supervised learning framework that allows Vision Transformers to learn visual representations without labeled data. It solves the problem of the high cost and effort required to create manually labeled datasets for training high-performance computer vision models.

How do I install DINO?

To install DINO, clone the GitHub repository, install PyTorch and torchvision, and then install the dependencies listed in the requirements.txt file using pip.

How does DINO compare to SimCLR or MoCo?

Unlike SimCLR and MoCo, DINO does not require negative samples during training. It uses a self-distillation process with a student-teacher network, which often results in features that are more naturally aligned with semantic object boundaries.

Can I use DINO for image segmentation?

DINO is exceptionally good for image segmentation because its self-attention maps automatically capture object boundaries without any supervision. You can extract these maps directly from the last layer of the ViT.

What are the prerequisites for running DINO?

The primary prerequisites are a Linux environment, a GPU with CUDA support, and a PyTorch installation. The training process is multi-crop augmentation-heavy and computationally intensive.

Is DINO open source?

Yes, DINO is released under the Apache License 2.0, which allows for wide use, modification, and distribution of the software.

Can I use DINO for video analysis?

DINO features are robust and stable enough to match keypoints across frames, making them useful for video object tracking and feature matching across different views of the same image.