{"id":16107185,"url":"https://github.com/againstentropy/dino-wrapper","last_synced_at":"2025-07-06T19:09:18.702Z","repository":{"id":209739922,"uuid":"666242802","full_name":"AgainstEntropy/DINO-Wrapper","owner":"AgainstEntropy","description":"A wrapper for any backbone to integrate DINO with few lines of code.","archived":false,"fork":false,"pushed_at":"2024-01-24T19:23:36.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T03:41:23.465Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AgainstEntropy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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":"2023-07-14T03:40:13.000Z","updated_at":"2023-11-28T21:26:03.000Z","dependencies_parsed_at":"2024-01-24T20:44:46.710Z","dependency_job_id":null,"html_url":"https://github.com/AgainstEntropy/DINO-Wrapper","commit_stats":null,"previous_names":["againstentropy/dino-wrapper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AgainstEntropy/DINO-Wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgainstEntropy%2FDINO-Wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgainstEntropy%2FDINO-Wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgainstEntropy%2FDINO-Wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgainstEntropy%2FDINO-Wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgainstEntropy","download_url":"https://codeload.github.com/AgainstEntropy/DINO-Wrapper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgainstEntropy%2FDINO-Wrapper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263957845,"owners_count":23535605,"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-10-09T19:15:27.979Z","updated_at":"2025-07-06T19:09:18.684Z","avatar_url":"https://github.com/AgainstEntropy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DINO-Wrapper\n\nA wrapper for any backbone to integrate DINO, a self-supervised method, with few lines of code.\n\nThis PyTorch implementation heavily references the repositories of [DINO](https://github.com/facebookresearch/dino/) and [DINO v2](https://github.com/facebookresearch/dinov2/).\n\nIf you find this repository useful, please consider giving a star :star: and citation :t-rex:\n\nDINO: \n[[`Repo`](https://github.com/facebookresearch/dino/)] \n[[`Blog`](https://ai.facebook.com/blog/dino-paws-computer-vision-with-self-supervised-transformers-and-10x-more-efficient-training)] \n[[`Paper`](https://arxiv.org/abs/2104.14294)] \n\nDINO v2: \n[[`Repo`](https://github.com/facebookresearch/dinov2/)] \n[[`Blog`](https://ai.facebook.com/blog/dino-v2-computer-vision-self-supervised-learning/)] \n[[`Paper`](https://arxiv.org/abs/2304.07193)] \n\n## Coming Updates\n\n- [ ] Use intermediate feature for computing dino loss\n\n- [ ] Cosider use EMA implementation from [timm](https://github.com/huggingface/pytorch-image-models/blob/main/timm/utils/model_ema.py), [MS](https://github.com/microsoft/unilm/blob/master/edgelm/fairseq/models/ema/ema.py), or [ema-pytorch](https://github.com/lucidrains/ema-pytorch).\n\n## Usage\n\nWithout DINO support:\n\n```python\nmodel, images = ...\noriginal_output = model(images)\nloss = criterion(original_output)\nloss.backward()\n...\n```\n\nWith DINO support:\n\n```diff\n+ from DINO_Wrapper import DINOWrapper\n\nmodel, images = ...\n+ dino_model = DINOWrapper(model)  # DINOv1 by default\n- original_output = model(images)\n- loss = criterion(original_output)\n+ original_output, dino_loss = dino_model(images)\n+ loss = criterion(original_output) + dino_loss\nloss.backward()\n...\n```\n\nNote that we expect the `original_output` is in the shape of `[B, D]`, where `B` is the batch size and `D` is the dimension of feature vectors, so that we can directly compute the DINO loss on the `original_output` by default.\n\n## Custome Configurations Supported\n\n```python\nfrom DINO_Wrapper import DINOWrapper, DINOConf\n\ndino_cfgs = DINOConf(\n    version='v2',\n    local_crops_number = 2,\n    global_crops_scale = (0.9, 1.), \n    global_crop_size = (480, 640),\n    local_crops_number = 8,\n    local_crops_scale = (0.6, 0.7), \n    local_crop_size = (240, 320),\n    preprocess_func = ...,\n    len_train_loader = len(train_loader),\n)\n\nmodel, images = ...\ndino_model = DINOWrapper(model, dino_cfgs)  # using DINOv2 now\noriginal_output, dino_loss = dino_model(images)\nloss = criterion(original_output) + dino_loss\nloss.backward()\n...\n```\n\n## Citations\n\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@misc{oquab2023dinov2,\n  title={DINOv2: Learning Robust Visual Features without Supervision},\n  author={Oquab, Maxime and Darcet, Timothée and Moutakanni, Theo and Vo, Huy V. and Szafraniec, Marc and Khalidov, Vasil and Fernandez, Pierre and Haziza, Daniel and Massa, Francisco and El-Nouby, Alaaeldin and Howes, Russell and Huang, Po-Yao and Xu, Hu and Sharma, Vasu and Li, Shang-Wen and Galuba, Wojciech and Rabbat, Mike and Assran, Mido and Ballas, Nicolas and Synnaeve, Gabriel and Misra, Ishan and Jegou, Herve and Mairal, Julien and Labatut, Patrick and Joulin, Armand and Bojanowski, Piotr},\n  journal={arXiv:2304.07193},\n  year={2023}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagainstentropy%2Fdino-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagainstentropy%2Fdino-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagainstentropy%2Fdino-wrapper/lists"}