Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

dino

> 编程语言
Open source

PyTorch code for Vision Transformers training with the Self-Supervised learning method DINO

7.6K stars0 likes2 views
WebsiteGitHub

About

PyTorch code for Vision Transformers training with the Self-Supervised learning method DINO

:new: Please check out our more recent DINOv2 effort in the same line of work.

Self-Supervised Vision Transformers with DINO

PyTorch implementation and pretrained models for DINO. For details, see Emerging Properties in Self-Supervised Vision Transformers.
[blogpost] [arXiv] [Yannic Kilcher's video]

Pretrained models

You can choose to download only the weights of the pretrained backbone used for downstream tasks, or the full checkpoint which contains backbone and projection head weights for both student and teacher networks. We also provide the backbone in onnx format, as well as detailed arguments and training/evaluation logs. Note that DeiT-S and ViT-S names refer exactly to the same architecture.

arch params k-nn linear download
ViT-S/16 21M 74.5% 77.0% backbone only full ckpt onnx args logs eval logs
ViT-S/8 21M 78.3% 79.7% backbone only full ckpt onnx args logs eval logs
ViT-B/16 85M 76.1% 78.2% backbone only full ckpt onnx args logs eval logs
ViT-B/8 85M 77.4% 80.1% backbone only full ckpt onnx args logs eval logs
ResNet-50 23M 67.5% 75.3% backbone only full ckpt onnx args logs eval logs

We also release XCiT models ([arXiv] [code]) trained with DINO:

arch params k-nn linear download
xcit_small_12_p16 26M 76.0% 77.8% backbone only full ckpt args logs eval
xcit_small_12_p8 26M 77.1% 79.2% backbone only full ckpt args logs eval
xcit_medium_24_p16 84M 76.4% 78.8% backbone only full ckpt args logs eval
xcit_medium_24_p8 84M 77.9% 80.3% backbone only full ckpt args logs eval

Pretrained models on PyTorch Hub

…

Training

Documentation

Please install PyTorch and download the ImageNet dataset. This codebase has been developed with python version 3.6, PyTorch version 1.7.1, CUDA 11.0 and torchvision 0.8.2. The exact arguments to reproduce the models presented in our paper can be found in the args column of the pretrained models section. For a glimpse at the full documentation of DINO training please run:

bash
python main_dino.py --help

Vanilla DINO training :sauropod:

Run DINO with ViT-small network on a single node with 8 GPUs for 100 epochs with the following command. Training time is 1.75 day and the resulting checkpoint should reach 69.3% on k-NN eval and 74.0% on linear eval. We provide training and linear evaluation logs (with batch size 256 at evaluation time) for this run to help reproducibility.

python -m torch.distributed.launch --nproc_per_node=8 main_dino.py --arch vit_small --data_path /path/to/imagenet/train --output_dir /path/to/saving_dir

Multi-node training

We use Slurm and submitit (pip install submitit). To train on 2 nodes with 8 GPUs each (total 16 GPUs):

bash
python run_with_submitit.py --nodes 2 --ngpus 8 --arch vit_small --data_path /path/to/imagenet/train --output_dir /path/to/saving_dir
DINO with ViT-base network.
bash
python run_with_submitit.py --nodes 2 --ngpus 8 --use_volta32 --arch vit_base  --data_path /path/to/imagenet/train --output_dir /path/to/saving_dir

Boosting DINO performance :t-rex:

You can improve the performance of the vanilla run by:

  • training for more epochs: --epochs 300,
  • increasing the teacher temperature: --teacher_temp 0.07 --warmup_teacher_temp_epochs 30.
  • removing last layer normalization (only safe with --arch vit_small): --norm_last_layer false,
Full command.
bash
python run_with_submitit.py --arch vit_small --epochs 300 --teacher_temp 0.07 --warmup_teacher_temp_epochs 30 --norm_last_layer false --data_path /path/to/imagenet/train --output_dir /path/to/saving_dir

The resulting pretrained model should reach 73.3% on k-NN eval and 76.0% on linear eval. Training time is 2.6 days with 16 GPUs. We provide training and linear evaluation logs (with batch size 256 at evaluation time) for this run to help reproducibility.

ResNet-50 and other convnets trainings

This code also works for training DINO on convolutional networks, like ResNet-50 for example. We highly recommend to adapt some optimization arguments in this case. For example following is a command

Issues· 113 open

View all issuesOpen on GitHub
  • #289

    Only reporting the accuracy of the first gpu by eval_linear.py

    Updated Aug 4, 2025
  • #273

    Loss is not decresing

    Updated Jul 12, 2025
  • #287

    loss increase sharply after the first epoch

    Updated Jul 12, 2025
  • #286

    ResNet backbone for DINO trainig

    Updated Jun 11, 2025
  • #284

    After fine-tuning, the model performs worse than the pre-trained model.

    Updated Feb 26, 2025
  • #225

    about the DINO training loss

    Updated Dec 12, 2024
  • #239

    How to get the feature map by using pretrained model.

    Updated Nov 28, 2024
  • #203

    train dino with human image for human Image retrieval got bad performance

    Updated Nov 22, 2024
  • #272

    Best features for image similarity

    Updated Nov 22, 2024
  • #228

    Help!Why the results of 'attention_visual.py' are different from those in the paper?

    Updated Nov 6, 2024

> Tags

Python

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言