{"id":13563275,"url":"https://github.com/ShirAmir/dino-vit-features","last_synced_at":"2025-04-03T19:32:50.827Z","repository":{"id":37785948,"uuid":"439102989","full_name":"ShirAmir/dino-vit-features","owner":"ShirAmir","description":"Official implementation for the paper \"Deep ViT Features as Dense Visual Descriptors\".","archived":false,"fork":false,"pushed_at":"2022-09-09T17:12:54.000Z","size":6138,"stargazers_count":391,"open_issues_count":12,"forks_count":45,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-04T15:52:29.356Z","etag":null,"topics":["co-segmentation","computer-vision","deep-learning","dino","part-segmentation","pytorch","semantic-correspondence","vision-transformers"],"latest_commit_sha":null,"homepage":"https://dino-vit-features.github.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShirAmir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-16T19:21:33.000Z","updated_at":"2024-11-01T09:19:39.000Z","dependencies_parsed_at":"2023-01-17T17:01:25.537Z","dependency_job_id":null,"html_url":"https://github.com/ShirAmir/dino-vit-features","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/ShirAmir%2Fdino-vit-features","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShirAmir%2Fdino-vit-features/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShirAmir%2Fdino-vit-features/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShirAmir%2Fdino-vit-features/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShirAmir","download_url":"https://codeload.github.com/ShirAmir/dino-vit-features/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247065470,"owners_count":20877785,"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":["co-segmentation","computer-vision","deep-learning","dino","part-segmentation","pytorch","semantic-correspondence","vision-transformers"],"created_at":"2024-08-01T13:01:17.200Z","updated_at":"2025-04-03T19:32:46.432Z","avatar_url":"https://github.com/ShirAmir.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# dino-vit-features\n[[paper](https://arxiv.org/abs/2112.05814)] [[project page](https://dino-vit-features.github.io)]\n\nOfficial implementation of the paper \"Deep ViT Features as Dense Visual Descriptors\".\n\n![teaser](./assets/teaser.png)\n\n\u003eWe demonstrate the effectiveness of deep features extracted from a self-supervised, pre-trained ViT model (DINO-ViT) as dense patch descriptors via real-world vision tasks: \n(a-b) co-segmentation \u0026 part co-segmentation: given a set of input images (e.g., 4 input images), we automatically co-segment semantically\ncommon foreground objects (e.g., animals), and then further partition them into common parts; (c-d) point correspondence:\ngiven a pair of input images, we automatically extract a sparse set of corresponding points. We tackle these tasks by applying\nonly lightweight, simple methodologies such as clustering or binning, to deep ViT features.\n\n## Setup\nOur code is developed in `pytorch` on and requires the following modules: `tqdm, faiss, timm, matplotlib, pydensecrf, opencv, scikit-learn`.\nWe use `python=3.9` but our code should be runnable on any version above `3.6`.\nWe recomment running our code with any CUDA supported GPU for faster performance.\nWe recommend setting the running environment via Anaconda by running the following commands:\n```\n$ conda env create -f env/dino-vit-feats-env.yml\n$ conda activate dino-vit-feats-env\n```\nOtherwise, run the following commands in your conda environment:\n```\n$ conda install pytorch torchvision torchaudio cudatoolkit=11 -c pytorch\n$ conda install tqdm\n$ conda install -c conda-forge faiss\n$ conda install -c conda-forge timm \n$ conda install matplotlib\n$ pip install opencv-python\n$ pip install git+https://github.com/lucasb-eyer/pydensecrf.git\n$ conda install -c anaconda scikit-learn\n```\n\n## ViT Extractor\n\n### Code Snippet\n```\nfrom extractor import ViTExtractor\nextractor = ViTExtractor()\n# imgs should be imagenet normalized tensors. shape BxCxHxW\ndescriptors = extractor.extract_descriptors(imgs) \n```\n---\nWe provide a wrapper class for a ViT model to extract dense visual descriptors in `extractor.py`.\nYou can extract descriptors to `.pt` files using the following command:\n```\npython extractor.py --image_path \u003cimage_path\u003e --output_path \u003coutput_path\u003e\n```\nYou can specify the pretrained model using the `--model` flag with the following options:\n* `dino_vits8`, `dino_vits16`, `dino_vitb8`, `dino_vitb16` from the [DINO repo](https://github.com/facebookresearch/dino).\n* `vit_small_patch8_224`, `vit_small_patch16_224`, `vit_base_patch8_224`, `vit_base_patch16_224` from the [timm repo](https://github.com/rwightman/pytorch-image-models/tree/master/timm).\n\nYou can specify the stride of patch extracting layer to increase resolution using the `--stride` flag.\n\n## Part Co-segmentation [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/shiramir/dino-vit-features/blob/main/part_cosegmentation.ipynb)\nWe provide a notebook for running on a single example in `part_cosegmentation.ipynb`. \n\nTo run on several image sets, arrange each set in a directory, inside a data root directory:\n\n```\n\u003csets_root_name\u003e\n|\n|_ \u003cset1_name\u003e\n|  |\n|  |_ img1.png\n|  |_ img2.png\n|   \n|_ \u003cset2_name\u003e\n   |\n   |_ img1.png\n   |_ img2.png\n   |_ img3.png\n...\n```\nThe following command will produce results in the specified `\u003csave_root_name\u003e`:\n```\npython part_cosegmentation.py --root_dir \u003csets_root_name\u003e --save_dir \u003csave_root_name\u003e\n```\n\n**Note:** The default configuration in `part_cosegmentation.ipynb` is suited for running on small sets (e.g. \u003c 10). Increase amount of `num_crop_augmentations` for more stable results (and increased runtime). The default configuration in `part_cosegmentation.py` is suited for larger sets (e.g. \u003e\u003e 10).\n\n## Co-segmentation [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/shiramir/dino-vit-features/blob/main/cosegmentation.ipynb)\nWe provide a notebook for running on a single example in `cosegmentation.ipynb`. \n\nTo run on several image sets, arrange each set in a directory, inside a data root directory:\n\n```\n\u003csets_root_name\u003e\n|\n|_ \u003cset1_name\u003e\n|  |\n|  |_ img1.png\n|  |_ img2.png\n|   \n|_ \u003cset2_name\u003e\n   |\n   |_ img1.png\n   |_ img2.png\n   |_ img3.png\n...\n```\nThe following command will produce results in the specified `\u003csave_root_name\u003e`:\n```\npython cosegmentation.py --root_dir \u003csets_root_name\u003e --save_dir \u003csave_root_name\u003e\n```\n\n\n## Point Correspondences [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/shiramir/dino-vit-features/blob/main/correspondences.ipynb)\nWe provide a notebook for running on a single example in `correpondences.ipynb`. \n\nTo run on several image pairs, arrange each image pair in a directory, inside a data root directory:\n\n```\n\u003cpairs_root_name\u003e\n|\n|_ \u003cpair1_name\u003e\n|  |\n|  |_ img1.png\n|  |_ img2.png\n|   \n|_ \u003cpair2_name\u003e\n   |\n   |_ img1.png\n   |_ img2.png\n...\n```\nThe following command will produce results in the specified `\u003csave_root_name\u003e`:\n```\npython correspondences.py --root_dir \u003cpairs_root_name\u003e --save_dir \u003csave_root_name\u003e\n```\n\n## Other Utilities\n### PCA\nWe provide code for computing the PCA of several images in a single directory:\n```\npython pca.py --root_dir \u003cimages_root_name\u003e --save_dir \u003csave_root_name\u003e\n```\n\n### Similarity Inspection\nWe provide code for interactively visualizing the similarity of a chosen descriptor in the source image to all target descriptors in a terget image.\n```\npython inspect_similarity --image_a \u003cpath_to_image_a\u003e --image_b \u003cpath_to_image_b\u003e\n```\n\n\n## Citation\nIf you found this repository useful please consider starring ⭐ and citing :\n```\n@article{amir2021deep,\n    author    = {Shir Amir and Yossi Gandelsman and Shai Bagon and Tali Dekel},\n    title     = {Deep ViT Features as Dense Visual Descriptors},\n    journal   = {arXiv preprint arXiv:2112.05814},\n    year      = {2021}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShirAmir%2Fdino-vit-features","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShirAmir%2Fdino-vit-features","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShirAmir%2Fdino-vit-features/lists"}