MetricMogul/single-image-dino-patch-matcher-and-cutout
0
Single-image DINOv3 patch matcher
Click any patch in an image. The app finds all patches with similar DINOv3 features in the same image and exports them as a transparent PNG.
What it's for
- Single-image co-segmentation / part discovery
- Probing what DINOv3 considers "the same thing" without training anything
- Building cutout datasets without a separate segmentation model
- Sanity-checking dense self-supervised features on your own data
How it works
- The image is resized so its long side matches the target (default 448 px), then rounded down to a multiple of the patch size (16). No padding — padded regions would match as "empty area" and pollute the similarity map.
- The image is passed through
facebook/dinov3-vits16-pretrain-lvd1689m. CLS and the 4 register tokens are stripped; only patch tokens remain. - Patch tokens are L2-normalized so cosine similarity is just a dot product.
- When you click a patch, its token is used as a query against all other patches. Patches that are both in top-k and above the threshold are kept.
- Kept patches are highlighted as a red mask. Cut selected patches exports them as a transparent PNG, cropped to the mask's bounding box.
The mask is the raw set of matched patches — no CRF, no connected components, no morphology. What you see is what DINOv3 actually represents.
Notes and limitations
- Edges are stepped because the mask lives on the 16×16 patch grid. This is a feature, not a bug — it shows you DINO's actual resolution.
- Top-k and threshold are combined (intersection), so tightening either shrinks the selection. Top-k controls how aggressive the match is; threshold controls how strict the similarity gate is.
- A single patch query can match semantically related but visually different regions (e.g. clicking on one wheel often selects all wheels). This is the whole point of self-supervised dense features.
Model
facebook/dinov3-vits16-pretrain-lvd1689m — patch size 16, 4 register tokens, ViT-S backbone. Runs comfortably on CPU; faster on GPU.
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
