Update README.md
Browse files
README.md
CHANGED
|
@@ -1,161 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
- **Official GitHub:** [facebookresearch/dinov3](https://github.com/facebookresearch/dinov3)
|
| 16 |
-
|
| 17 |
-
**Note:**
|
| 18 |
-
The DINOv3 model weights require access approval.
|
| 19 |
-
You can request access via the [Meta Research page](https://ai.meta.com/resources/models-and-libraries/dinov3-downloads/) or by selecting the desired model on [Hugging Face model collection](https://huggingface.co/collections/facebook/dinov3-68924841bd6b561778e31009).
|
| 20 |
-
|
| 21 |
-
## Features
|
| 22 |
-
|
| 23 |
-
- **Interactive Visualization:** Click on image patches or use arrow keys to explore patch similarity heatmaps.
|
| 24 |
-
- **Single or Two-Image Mode:** If one image is specified, shows self-similarity. If two images are specified, shows both self-similarity and cross-image similarity overlays interactively.
|
| 25 |
-
- **Image Preprocessing:** Loads and pads images without resizing, preserving the original aspect ratio.
|
| 26 |
-
- **Cosine Similarity Calculation:** Computes and visualizes cosine similarity between image patches.
|
| 27 |
-
- **Robust Fallback:** If an image URL fails to load, a default image is used.
|
| 28 |
-
|
| 29 |
-
## Installation
|
| 30 |
-
|
| 31 |
-
Install dependencies with:
|
| 32 |
-
|
| 33 |
-
```bash
|
| 34 |
-
pip install -r requirements.txt
|
| 35 |
-
```
|
| 36 |
-
|
| 37 |
-
## Model Selection
|
| 38 |
-
|
| 39 |
-
You can choose from several DINOv3 models available on Hugging Face (click to view each model card):
|
| 40 |
-
|
| 41 |
-
LVD-1689M Dataset (Web data)
|
| 42 |
-
- ViT
|
| 43 |
-
- [facebook/dinov3-vit7b16-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-vit7b16-pretrain-lvd1689m)
|
| 44 |
-
- [facebook/dinov3-vits16-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-vits16-pretrain-lvd1689m)
|
| 45 |
-
- [facebook/dinov3-vits16plus-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-vits16plus-pretrain-lvd1689m)
|
| 46 |
-
- [facebook/dinov3-vitb16-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-vitb16-pretrain-lvd1689m)
|
| 47 |
-
- [facebook/dinov3-vitl16-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-vitl16-pretrain-lvd1689m)
|
| 48 |
-
- [facebook/dinov3-vith16plus-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-vith16plus-pretrain-lvd1689m)
|
| 49 |
-
|
| 50 |
-
- ConvNeXt
|
| 51 |
-
- [facebook/dinov3-convnext-tiny-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-convnext-tiny-pretrain-lvd1689m)
|
| 52 |
-
- [facebook/dinov3-convnext-small-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-convnext-small-pretrain-lvd1689m)
|
| 53 |
-
- [facebook/dinov3-convnext-base-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-convnext-base-pretrain-lvd1689m)
|
| 54 |
-
- [facebook/dinov3-convnext-large-pretrain-lvd1689m](https://huggingface.co/facebook/dinov3-convnext-large-pretrain-lvd1689m)
|
| 55 |
-
|
| 56 |
-
SAT-493M Dataset (Satellite data)
|
| 57 |
-
- ViT
|
| 58 |
-
- [facebook/dinov3-vitl16-pretrain-sat493m](https://huggingface.co/facebook/dinov3-vitl16-pretrain-sat493m)
|
| 59 |
-
- [facebook/dinov3-vit7b16-pretrain-sat493m](https://huggingface.co/facebook/dinov3-vit7b16-pretrain-sat493m)
|
| 60 |
-
|
| 61 |
-
## Usage
|
| 62 |
-
|
| 63 |
-
### Gradio app
|
| 64 |
-
|
| 65 |
-
Run the Gradio app:
|
| 66 |
-
|
| 67 |
-
```bash
|
| 68 |
-
python app.py
|
| 69 |
-
```
|
| 70 |
-
|
| 71 |
-
After runnig the app, go to [http://localhost:7860/](http://localhost:7860/) to see the app running.
|
| 72 |
-
|
| 73 |
-
Then:
|
| 74 |
-
- Choose Dataset and model name
|
| 75 |
-
- For Single image similarity:
|
| 76 |
-
- Choose only one file or URL
|
| 77 |
-
- For 2 image similarity:
|
| 78 |
-
- Choose images from file and/or URL
|
| 79 |
-
- Click button "Initialize / Update "
|
| 80 |
-
- Select the desired patch from the image
|
| 81 |
-
- Watch the results
|
| 82 |
-
|
| 83 |
-
**Note:**
|
| 84 |
-
*Overlay alpha* is the intensity of the overlay of patches on top of image
|
| 85 |
-
|
| 86 |
-
### Python Script
|
| 87 |
-
|
| 88 |
-
Run the interactive viewer with the default COCO image:
|
| 89 |
-
|
| 90 |
-
```bash
|
| 91 |
-
python DINOv3CosSimilarity.py
|
| 92 |
-
```
|
| 93 |
-
|
| 94 |
-
#### Single Image Mode
|
| 95 |
-
|
| 96 |
-
Specify your own image (local path or URL):
|
| 97 |
-
|
| 98 |
-
```bash
|
| 99 |
-
python DINOv3CosSimilarity.py --image path/to/your/image.jpg
|
| 100 |
-
python DINOv3CosSimilarity.py --image https://yourdomain.com/image.png
|
| 101 |
-
```
|
| 102 |
-
|
| 103 |
-
#### Two Image Mode
|
| 104 |
-
|
| 105 |
-
Specify two images (local paths or URLs):
|
| 106 |
-
|
| 107 |
-
```bash
|
| 108 |
-
python DINOv3CosSimilarity.py --image1 path/to/image1.jpg --image2 path/to/image2.jpg
|
| 109 |
-
python DINOv3CosSimilarity.py --image1 https://yourdomain.com/image1.png --image2 https://yourdomain.com/image2.png
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
#### Model Selection
|
| 113 |
-
|
| 114 |
-
Specify the model with `--model` (default is vits16):
|
| 115 |
-
|
| 116 |
-
```bash
|
| 117 |
-
python DINOv3CosSimilarity.py --model facebook/dinov3-vitb16-pretrain-lvd1689m
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
#### Other Options
|
| 121 |
-
|
| 122 |
-
- `--show_grid` : Draw patch grid
|
| 123 |
-
- `--annotate_indices` : Write patch indices on cells
|
| 124 |
-
- `--overlay_alpha <float>` : Set heatmap alpha (default 0.55)
|
| 125 |
-
- `--patch_size <int>` : Override patch size (default: model's patch size)
|
| 126 |
-
|
| 127 |
-
#### Controls
|
| 128 |
-
|
| 129 |
-
- Mouse click to select a patch
|
| 130 |
-
- Arrow keys to move selection
|
| 131 |
-
- '1', '2', or 't' to switch active image (in two-image mode)
|
| 132 |
-
- 'q' to quit
|
| 133 |
-
|
| 134 |
-
## Demo Single Image
|
| 135 |
-
|
| 136 |
-

|
| 137 |
-
|
| 138 |
-
## Demo 2 Images
|
| 139 |
-
|
| 140 |
-

|
| 141 |
-
|
| 142 |
-
### Jupyter Notebook
|
| 143 |
-
|
| 144 |
-
1. Open `PatchCosSimilarity.ipynb` in Jupyter Notebook.
|
| 145 |
-
2. Run the cells to load an image and visualize patch similarities.
|
| 146 |
-
3. Set `url1` for single-image mode, or both `url1` and `url2` for two-image mode.
|
| 147 |
-
4. If an image fails to load, a default image will be used automatically.
|
| 148 |
-
5. Set the `model_id` variable to any of the models listed above (see commented lines at the top of the notebook).
|
| 149 |
-
|
| 150 |
-
**Notebook Controls:**
|
| 151 |
-
- Mouse click to select a patch
|
| 152 |
-
- Arrow keys to move selection
|
| 153 |
-
- '1', '2', or 't' to switch active image (in two-image mode)
|
| 154 |
-
|
| 155 |
-
## License
|
| 156 |
-
|
| 157 |
-
This project is licensed under the MIT License. See the `LICENSE` file for details.
|
| 158 |
-
|
| 159 |
-
## Acknowledgments
|
| 160 |
-
|
| 161 |
-
This project utilizes the DINOv3 model from Hugging Face's Transformers library, along with PyTorch, Matplotlib, and Pillow
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: DINOv3 Interactive Patch Cosine Similarity
|
| 3 |
+
emoji: 🏃
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.43.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: Interactive tool to visualize patch-wise similarity in image
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|