{"id":13573192,"url":"https://github.com/facebookresearch/dino","last_synced_at":"2025-05-14T05:10:38.934Z","repository":{"id":37638027,"uuid":"360066433","full_name":"facebookresearch/dino","owner":"facebookresearch","description":"PyTorch code for Vision Transformers training with the Self-Supervised learning method DINO","archived":false,"fork":false,"pushed_at":"2024-07-03T16:21:59.000Z","size":25006,"stargazers_count":6751,"open_issues_count":111,"forks_count":947,"subscribers_count":65,"default_branch":"main","last_synced_at":"2025-04-09T02:15:14.941Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facebookresearch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-21T07:09:37.000Z","updated_at":"2025-04-08T14:40:34.000Z","dependencies_parsed_at":"2023-02-03T18:46:11.416Z","dependency_job_id":"5a367b61-757c-467a-8f78-6864954a7793","html_url":"https://github.com/facebookresearch/dino","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fdino","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fdino/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fdino/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebookresearch%2Fdino/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facebookresearch","download_url":"https://codeload.github.com/facebookresearch/dino/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076850,"owners_count":22010611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:00:31.636Z","updated_at":"2025-05-14T05:10:38.911Z","avatar_url":"https://github.com/facebookresearch.png","language":"Python","funding_links":[],"categories":["Python","Vision Model Backbone","Resources","其他_机器视觉","PyTorch Models","Contrastive \u0026 Self-Supervised Learning","Self-Supervision"],"sub_categories":["[TVCG24] NIS-SLAM: Neural Implicit Semantic RGB-D SLAM for 3D Consistent Scene Understanding","网络服务_其他","Computer Vision"],"readme":":new: *Please check out our more recent [DINOv2](https://github.com/facebookresearch/dinov2) effort in the same line of work.*\n\n# Self-Supervised Vision Transformers with DINO\n\nPyTorch implementation and pretrained models for DINO. For details, see **Emerging Properties in Self-Supervised Vision Transformers**.  \n[[`blogpost`](https://ai.facebook.com/blog/dino-paws-computer-vision-with-self-supervised-transformers-and-10x-more-efficient-training)] [[`arXiv`](https://arxiv.org/abs/2104.14294)] [[`Yannic Kilcher's video`](https://www.youtube.com/watch?v=h3ij3F3cPIk)]\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"100%\" alt=\"DINO illustration\" src=\".github/dino.gif\"\u003e\n\u003c/div\u003e\n\n## Pretrained models\nYou 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.\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003earch\u003c/th\u003e\n    \u003cth\u003eparams\u003c/th\u003e\n    \u003cth\u003ek-nn\u003c/th\u003e\n    \u003cth\u003elinear\u003c/th\u003e\n    \u003cth colspan=\"6\"\u003edownload\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-S/16\u003c/td\u003e\n    \u003ctd\u003e21M\u003c/td\u003e\n    \u003ctd\u003e74.5%\u003c/td\u003e\n    \u003ctd\u003e77.0%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/dino_deitsmall16_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/dino_deitsmall16_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/dino_deits16.onnx\"\u003eonnx\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/dino_deitsmall16_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/dino_deitsmall16_pretrain_eval_linear_log.txt\"\u003eeval logs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-S/8\u003c/td\u003e\n    \u003ctd\u003e21M\u003c/td\u003e\n    \u003ctd\u003e78.3%\u003c/td\u003e\n    \u003ctd\u003e79.7%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/dino_deitsmall8_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/dino_deitsmall8_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/dino_deits8.onnx\"\u003eonnx\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/dino_deitsmall8_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/dino_deitsmall8_pretrain_eval_linear_log.txt\"\u003eeval logs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-B/16\u003c/td\u003e\n    \u003ctd\u003e85M\u003c/td\u003e\n    \u003ctd\u003e76.1%\u003c/td\u003e\n    \u003ctd\u003e78.2%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/dino_vitbase16_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/dino_vitbase16_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/dino_vitb16.onnx\"\u003eonnx\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/dino_vitbase16_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/dino_vitbase16_pretrain_eval_linear_log.txt\"\u003eeval logs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-B/8\u003c/td\u003e\n    \u003ctd\u003e85M\u003c/td\u003e\n    \u003ctd\u003e77.4%\u003c/td\u003e\n    \u003ctd\u003e80.1%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/dino_vitbase8_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/dino_vitbase8_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/dino_vitb8.onnx\"\u003eonnx\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/dino_vitbase8_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/dino_vitbase8_pretrain_eval_linear_log.txt\"\u003eeval logs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eResNet-50\u003c/td\u003e\n    \u003ctd\u003e23M\u003c/td\u003e\n    \u003ctd\u003e67.5%\u003c/td\u003e\n    \u003ctd\u003e75.3%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/dino_resnet50_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/dino_resnet50_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/dino_resnet50.onnx\"\u003eonnx\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/dino_resnet50_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/dino_resnet50_pretrain_eval_linear_log.txt\"\u003eeval logs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nWe also release XCiT models ([[`arXiv`](https://arxiv.org/abs/2106.09681)] [[`code`](https://github.com/facebookresearch/xcit)]) trained with DINO:\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003earch\u003c/th\u003e\n    \u003cth\u003eparams\u003c/th\u003e\n    \u003cth\u003ek-nn\u003c/th\u003e\n    \u003cth\u003elinear\u003c/th\u003e\n    \u003cth colspan=\"5\"\u003edownload\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_small_12_p16\u003c/td\u003e\n    \u003ctd\u003e26M\u003c/td\u003e\n    \u003ctd\u003e76.0%\u003c/td\u003e\n    \u003ctd\u003e77.8%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p16_pretrain/dino_xcit_small_12_p16_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p16_pretrain/dino_xcit_small_12_p16_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p16_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p16_pretrain/dino_xcit_small_12_p16_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p16_pretrain/dino_xcit_small_12_p16_pretrain_eval_linear_log.txt\"\u003eeval\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_small_12_p8\u003c/td\u003e\n    \u003ctd\u003e26M\u003c/td\u003e\n    \u003ctd\u003e77.1%\u003c/td\u003e\n    \u003ctd\u003e79.2%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p8_pretrain/dino_xcit_small_12_p8_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p8_pretrain/dino_xcit_small_12_p8_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p8_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p8_pretrain/dino_xcit_small_12_p8_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p8_pretrain/dino_xcit_small_12_p8_pretrain_eval_linear_log.txt\"\u003eeval\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_medium_24_p16\u003c/td\u003e\n    \u003ctd\u003e84M\u003c/td\u003e\n    \u003ctd\u003e76.4%\u003c/td\u003e\n    \u003ctd\u003e78.8%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p16_pretrain/dino_xcit_medium_24_p16_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p16_pretrain/dino_xcit_medium_24_p16_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p16_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p16_pretrain/dino_xcit_medium_24_p16_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p16_pretrain/dino_xcit_medium_24_p16_pretrain_eval_linear_log.txt\"\u003eeval\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_medium_24_p8\u003c/td\u003e\n    \u003ctd\u003e84M\u003c/td\u003e\n    \u003ctd\u003e77.9%\u003c/td\u003e\n    \u003ctd\u003e80.3%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p8_pretrain/dino_xcit_medium_24_p8_pretrain.pth\"\u003ebackbone only\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p8_pretrain/dino_xcit_medium_24_p8_pretrain_full_checkpoint.pth\"\u003efull ckpt\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p8_pretrain/args.txt\"\u003eargs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p8_pretrain/dino_xcit_medium_24_p8_pretrain_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p8_pretrain/dino_xcit_medium_24_p8_pretrain_eval_linear_log.txt\"\u003eeval\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### Pretrained models on PyTorch Hub\n```python\nimport torch\nvits16 = torch.hub.load('facebookresearch/dino:main', 'dino_vits16')\nvits8 = torch.hub.load('facebookresearch/dino:main', 'dino_vits8')\nvitb16 = torch.hub.load('facebookresearch/dino:main', 'dino_vitb16')\nvitb8 = torch.hub.load('facebookresearch/dino:main', 'dino_vitb8')\nxcit_small_12_p16 = torch.hub.load('facebookresearch/dino:main', 'dino_xcit_small_12_p16')\nxcit_small_12_p8 = torch.hub.load('facebookresearch/dino:main', 'dino_xcit_small_12_p8')\nxcit_medium_24_p16 = torch.hub.load('facebookresearch/dino:main', 'dino_xcit_medium_24_p16')\nxcit_medium_24_p8 = torch.hub.load('facebookresearch/dino:main', 'dino_xcit_medium_24_p8')\nresnet50 = torch.hub.load('facebookresearch/dino:main', 'dino_resnet50')\n```\n\n## Training\n\n### Documentation\nPlease install [PyTorch](https://pytorch.org/) and download the [ImageNet](https://imagenet.stanford.edu/) 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](https://github.com/facebookresearch/dino#pretrained-models). For a glimpse at the full documentation of DINO training please run:\n```\npython main_dino.py --help\n```\n\n### Vanilla DINO training :sauropod:\nRun 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](https://dl.fbaipublicfiles.com/dino/example_runs_logs/dino_vanilla_deitsmall16_log.txt) and [linear evaluation](https://dl.fbaipublicfiles.com/dino/example_runs_logs/dino_vanilla_deitsmall16_eval.txt) logs (with batch size 256 at evaluation time) for this run to help reproducibility.\n```\npython -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\n```\n\n### Multi-node training\nWe use Slurm and [submitit](https://github.com/facebookincubator/submitit) (`pip install submitit`). To train on 2 nodes with 8 GPUs each (total 16 GPUs):\n```\npython run_with_submitit.py --nodes 2 --ngpus 8 --arch vit_small --data_path /path/to/imagenet/train --output_dir /path/to/saving_dir\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\nDINO with ViT-base network.\n\u003c/summary\u003e\n\n```\npython 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\n```\n\n\u003c/details\u003e\n\n### Boosting DINO performance :t-rex:\nYou can improve the performance of the vanilla run by:\n- training for more epochs: `--epochs 300`,\n- increasing the teacher temperature: `--teacher_temp 0.07 --warmup_teacher_temp_epochs 30`.\n- removing last layer normalization (only safe with `--arch vit_small`): `--norm_last_layer false`,\n\n\u003cdetails\u003e\n\u003csummary\u003e\nFull command.\n\u003c/summary\u003e\n\n```\npython 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\n```\n\n\u003c/details\u003e\n\nThe 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](https://dl.fbaipublicfiles.com/dino/example_runs_logs/dino_boost_deitsmall16_log.txt) and [linear evaluation](https://dl.fbaipublicfiles.com/dino/example_runs_logs/dino_boost_deitsmall16_eval.txt) logs (with batch size 256 at evaluation time) for this run to help reproducibility.\n\n### ResNet-50 and other convnets trainings\nThis 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 to train DINO on ResNet-50 on a single node with 8 GPUs for 100 epochs. We provide [training logs](https://dl.fbaipublicfiles.com/dino/example_runs_logs/dino_rn50_log.txt) and [final checkpoint](https://dl.fbaipublicfiles.com/dino/example_runs_logs/dino_rn50_checkpoint.pth) for this run.\n```\npython -m torch.distributed.launch --nproc_per_node=8 main_dino.py --arch resnet50 --optimizer sgd --lr 0.03 --weight_decay 1e-4 --weight_decay_end 1e-4 --global_crops_scale 0.14 1 --local_crops_scale 0.05 0.14 --data_path /path/to/imagenet/train --output_dir /path/to/saving_dir\n```\n\n## Self-attention visualization\nYou can look at the self-attention of the [CLS] token on the different heads of the last layer by running:\n```\npython visualize_attention.py\n```\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"100%\" alt=\"Self-attention from a Vision Transformer with 8x8 patches trained with DINO\" src=\".github/attention_maps.png\"\u003e\n\u003c/div\u003e\n\n## Self-attention video generation\nYou can generate videos like the one on the blog post with `video_generation.py`.\n\nhttps://user-images.githubusercontent.com/46140458/116817761-47885e80-ab68-11eb-9975-d61d5a919e13.mp4\n\nExtract frames from input video and generate attention video:\n```\npython video_generation.py  --pretrained_weights dino_deitsmall8_pretrain.pth \\\n    --input_path input/video.mp4 \\\n    --output_path output/ \\\n    --fps 25\n```\n\nUse folder of frames already extracted and generate attention video:\n```\npython video_generation.py  --pretrained_weights dino_deitsmall8_pretrain.pth \\\n    --input_path output/frames/ \\\n    --output_path output/ \\\n    --resize 256 \\\n```\n\nOnly generate video from folder of attention maps images:\n```\npython video_generation.py --input_path output/attention \\\n    --output_path output/ \\\n    --video_only \\\n    --video_format avi\n```\n\n\n## Evaluation: k-NN classification on ImageNet\nTo evaluate a simple k-NN classifier with a single GPU on a pre-trained model, run:\n```\npython -m torch.distributed.launch --nproc_per_node=1 eval_knn.py --data_path /path/to/imagenet\n```\nIf you choose not to specify `--pretrained_weights`, then DINO reference weights are used by default. If you want instead to evaluate checkpoints from a run of your own, you can run for example:\n```\npython -m torch.distributed.launch --nproc_per_node=1 eval_knn.py --pretrained_weights /path/to/checkpoint.pth --checkpoint_key teacher --data_path /path/to/imagenet \n```\n\n## Evaluation: Linear classification on ImageNet\nTo train a supervised linear classifier on frozen weights on a single node with 8 gpus, run:\n```\npython -m torch.distributed.launch --nproc_per_node=8 eval_linear.py --data_path /path/to/imagenet\n```\n\nWe release the logs and weights from evaluating the different models:\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003earch\u003c/th\u003e\n    \u003cth\u003etop-1 ImageNet\u003c/th\u003e\n    \u003cth colspan=\"2\"\u003elinear evaluation\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-S/16\u003c/td\u003e\n    \u003ctd\u003e77.0%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/dino_deitsmall16_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall16_pretrain/dino_deitsmall16_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-S/8\u003c/td\u003e\n    \u003ctd\u003e79.7%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/dino_deitsmall8_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_deitsmall8_pretrain/dino_deitsmall8_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-B/16\u003c/td\u003e\n    \u003ctd\u003e78.2%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/dino_vitbase16_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase16_pretrain/dino_vitbase16_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eViT-B/8\u003c/td\u003e\n    \u003ctd\u003e80.1%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/dino_vitbase8_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_vitbase8_pretrain/dino_vitbase8_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_small_12_p16\u003c/td\u003e\n    \u003ctd\u003e77.8%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p16_pretrain/dino_xcit_small_12_p16_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p16_pretrain/dino_xcit_small_12_p16_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_small_12_p8\u003c/td\u003e\n    \u003ctd\u003e79.2%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p8_pretrain/dino_xcit_small_12_p8_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_small_12_p8_pretrain/dino_xcit_small_12_p8_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_medium_24_p16\u003c/td\u003e\n    \u003ctd\u003e78.8%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p16_pretrain/dino_xcit_medium_24_p16_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p16_pretrain/dino_xcit_medium_24_p16_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003excit_medium_24_p8\u003c/td\u003e\n    \u003ctd\u003e80.3%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p8_pretrain/dino_xcit_medium_24_p8_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_xcit_medium_24_p8_pretrain/dino_xcit_medium_24_p8_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eResNet-50\u003c/td\u003e\n    \u003ctd\u003e75.3%\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/dino_resnet50_linearweights.pth\"\u003elinear weights\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://dl.fbaipublicfiles.com/dino/dino_resnet50_pretrain/dino_resnet50_pretrain_eval_linear_log.txt\"\u003elogs\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nYou can check the performance of the pretrained weights on ImageNet validation set by running the following command lines:\n```\npython eval_linear.py --evaluate --arch vit_small --patch_size 16 --data_path /path/to/imagenet/train\n```\n\n```\npython eval_linear.py --evaluate --arch vit_small --patch_size 8 --data_path /path/to/imagenet/train\n```\n\n```\npython eval_linear.py --evaluate --arch vit_base --patch_size 16 --n_last_blocks 1 --avgpool_patchtokens true --data_path /path/to/imagenet/train\n```\n\n```\npython eval_linear.py --evaluate --arch vit_base --patch_size 8 --n_last_blocks 1 --avgpool_patchtokens true --data_path /path/to/imagenet/train\n```\n\n```\npython eval_linear.py --evaluate --arch resnet50 --data_path /path/to/imagenet/train\n```\n\n## Evaluation: DAVIS 2017 Video object segmentation\nPlease verify that you're using pytorch version 1.7.1 since we are not able to reproduce the results with most recent pytorch 1.8.1 at the moment.\n\n**Step 1: Prepare DAVIS 2017 data**  \n```\ncd $HOME\ngit clone https://github.com/davisvideochallenge/davis-2017 \u0026\u0026 cd davis-2017\n./data/get_davis.sh\n```\n\n**Step 2: Video object segmentation**  \n```\npython eval_video_segmentation.py --data_path $HOME/davis-2017/DAVIS/ --output_dir /path/to/saving_dir\n```\n\n**Step 3: Evaluate the obtained segmentation**  \n```\ngit clone https://github.com/davisvideochallenge/davis2017-evaluation $HOME/davis2017-evaluation\npython $HOME/davis2017-evaluation/evaluation_method.py --task semi-supervised --results_path /path/to/saving_dir --davis_path $HOME/davis-2017/DAVIS/\n```\n\n## Evaluation: Image Retrieval on revisited Oxford and Paris\nStep 1: Prepare revisited Oxford and Paris by following [this repo](https://github.com/filipradenovic/revisitop).\n\nStep 2: Image retrieval (if you do not specify weights with `--pretrained_weights` then by default [DINO weights pretrained on Google Landmark v2 dataset](https://dl.fbaipublicfiles.com/dino/dino_vitsmall16_googlelandmark_pretrain/dino_vitsmall16_googlelandmark_pretrain.pth) will be used).\n\nParis:\n```\npython -m torch.distributed.launch --use_env --nproc_per_node=1 eval_image_retrieval.py --imsize 512 --multiscale 1 --data_path /path/to/revisited_paris_oxford/ --dataset rparis6k\n```\n\nOxford:\n```\npython -m torch.distributed.launch --use_env --nproc_per_node=1 eval_image_retrieval.py --imsize 224 --multiscale 0 --data_path /path/to/revisited_paris_oxford/ --dataset roxford5k\n```\n\n## Evaluation: Copy detection on Copydays\nStep 1: Prepare [Copydays dataset](https://lear.inrialpes.fr/~jegou/data.php#copydays).\n\nStep 2 (opt): Prepare a set of image distractors and a set of images on which to learn the whitening operator.\nIn our paper, we use 10k random images from YFCC100M as distractors and 20k random images from YFCC100M (different from the distractors) for computing the whitening operation.\n\nStep 3: Run copy detection:\n```\npython -m torch.distributed.launch --use_env --nproc_per_node=1 eval_copy_detection.py --data_path /path/to/copydays/ --whitening_path /path/to/whitening_data/ --distractors_path /path/to/distractors/\n```\nWe report result on the strong subset. For example in the stdout from the command above we get: `eval on strong mAP=0.858`.\n\n## License\nThis repository is released under the Apache 2.0 license as found in the [LICENSE](LICENSE) file.\n\n## Citation\nIf you find this repository useful, please consider giving a star :star: and citation :t-rex::\n```\n@inproceedings{caron2021emerging,\n  title={Emerging Properties in Self-Supervised Vision Transformers},\n  author={Caron, Mathilde and Touvron, Hugo and Misra, Ishan and J\\'egou, Herv\\'e  and Mairal, Julien and Bojanowski, Piotr and Joulin, Armand},\n  booktitle={Proceedings of the International Conference on Computer Vision (ICCV)},\n  year={2021}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebookresearch%2Fdino","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacebookresearch%2Fdino","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebookresearch%2Fdino/lists"}