DINO-KNN: Training-Free Multiclass In-Context Segmentation via Nearest Neighbors

Hussain Alasmawi, Numan Saeed, Mohammad YaqubarXiv 2026

TL;DR

DINO-KNN performs multiclass image segmentation without any task-specific training by simply comparing image patches to a small "memory bank" of labeled examples. By using a powerful frozen foundation model (DINOv3) and a classic $k$-Nearest Neighbors ($k$-NN) voting rule, it outperforms complex, multi-stage pipelines while running twice as fast.

What Problem Does This Paper Address?

In the world of computer vision, In-Context Segmentation (ICS) is the "show and tell" of AI. Instead of training a model on millions of images to recognize a specific object, you give it a few labeled examples (the "context") and ask it to find those same objects in a new "target" image.

While recent "training-free" methods have made strides by using massive foundation models like DINOv2 or Segment Anything (SAM), they have two major hangups:

  1. The Binary Bottleneck: Most current methods can only look for one class at a time. If you want to find "cars," "trees," and "roads," you have to run the model three separate times and then try to stitch the results together.
  2. The Data Plateau: Curiously, many existing models don't get much smarter when you give them more examples. After about five reference images, their performance flatlines.

The authors of DINO-KNN asked a provocative question: Can we ditch the complex pipelines and just use a simple, joint decision rule to handle multiple classes and actually benefit from more data?

Methods

The architecture of DINO-KNN is refreshingly simple, relying on "non-parametric" classification—which is a fancy way of saying it makes decisions based on raw data points rather than learned weights.

Figure 2. Overview of DINO-KNN with R=3 references. References and target are encoded by a frozen DINOv3 ViT-L/16 and position- ally debiased. All labeled reference patches form one memory. The memory panel shows the reference patches around the marked target patch: a dot closer to the center is more similar to it, and the circle encloses its k nearest patches. Their inverse-distance votes yield the patch’s class scores. The vote is repeated for every target patch, and the patch label map is resized to the image.
  1. Feature Extraction: It uses a frozen DINOv3 encoder to turn every $16 \times 16$ pixel patch of an image into a high-dimensional vector (a feature).
  2. Positional Debiasing: Foundation models often "remember" where an object usually sits in a frame. To prevent the model from thinking a "storage tank" can only exist in the bottom-left corner, the authors apply a mathematical "debiasing" step that strips away this spatial prior, focusing purely on what the object is, not where it is.
  3. Labeled Patch Memory: Every labeled patch from the reference images is stored in a single memory bank. Crucially, they don't average these patches into a "prototype." They keep every single one, preserving all the different ways a "harbor" or a "fish" might look.
  4. $k$-NN Voting: For every patch in the target image, the model finds the $k$ (usually 15) most similar patches in its memory. These neighbors cast a distance-weighted vote to decide the patch's label. All classes are decided in one single pass.

Datasets

The researchers evaluated DINO-KNN across eight diverse datasets, split into two categories:

  • Natural Images: COCO-20i (general objects), LVIS-92i (rare objects), SUIM (underwater), and iSAID-5i (aerial views).
  • Medical Images: CAMUS (cardiac ultrasound), FASS (fetal abdomen), PSFHS (maternal ultrasound), and EndoVis17 (robotic surgery).

This mix is important because medical images often have very consistent layouts, whereas natural images are chaotic and unpredictable.

Key Insights and Ideas

  • Raw Data > Prototypes: Most models try to summarize a class (e.g., "all cats") into one average vector. DINO-KNN shows that keeping individual examples is far superior. If you have 15 pictures of a cat from different angles, an "average cat" looks like a blur, but $k$-NN can find the specific angle that matches your target image.
  • The Power of Scaling: Because DINO-KNN keeps every patch, it actually gets better as you add more reference images. While baselines plateaued, DINO-KNN's accuracy kept climbing all the way up to 15 references.
  • Simplicity is Speed: By avoiding "mask decoders" (extra AI layers that refine shapes) and multi-pass processing, the model is significantly more efficient.

Key Results

DINO-KNN achieved the best average performance (mIoU) across all eight datasets at every number of reference images ($R$).

  • Accuracy Growth: On average, its score jumped from 37.8 mIoU with one reference to 56.2 mIoU with 15 references. For comparison, the strongest baseline (INSID3) only rose from 36.1 to 42.9.
  • Speed: It is 2.1x faster than the previous state-of-the-art training-free method (INSID3).
  • Efficiency: It uses significantly less GPU memory (1.5–1.7 GB) compared to methods using the Segment Anything Model (5.6–6.8 GB).
Figure 1. The accuracy of DINO-KNN grows with the number of reference (R) images. (a) A target segmented with R=1, 5, and 15 reference images. (b) mIoU at R=1 and R=15 on eight datasets over three reference seeds. On average, the mIoU rises by 18.4 points for DINO-KNN and by 6.8 for INSID3.

Limitations and Future Work

  • Small Objects: Since the model works on $16 \times 16$ patches, it can struggle with very tiny objects that are smaller than a single patch.
  • Blocky Edges: Because there is no "mask decoder" or boundary refinement step, the edges of the segmented objects can look a bit "pixelated" or blocky at the patch level.
  • Class Imbalance: If a class has very few patches in the reference images, it can be "outvoted" by a more common class (like the background).

The authors suggest that future work could focus on adding spatial detail to improve these fine boundaries without sacrificing the simplicity and speed that makes DINO-KNN so effective.

Summary updated

Abstract

In-context segmentation (ICS) segments a target image given a few annotated reference images. Recent training-free methods built on frozen foundation models segment one class at a time and gain little from additional references. We study the multiclass, multi-reference setting and ask how far a simple joint decision rule can go. We introduce DINO-KNN, which stores every labeled reference patch of a frozen DINOv3 encoder in a single memory and labels each target patch by a distance-weighted vote of its k nearest neighbors. All classes are predicted in a single pass, with one label per pixel, without training or a mask decoder. We evaluate on eight datasets, four natural and four medical, with R=1 to 15 reference images and three reference seeds. DINO-KNN achieves the best average mIoU at every R; it is the best method on six of the eight datasets from R=3 and on seven of the eight from R=7. Its accuracy continues to grow with the number of references, from 37.8 mIoU at R=1 to 56.2 at R=15, while the strongest baseline, INSID3, rises from 36.1 to 42.9. DINO-KNN is also 2.1x faster than INSID3. The code will be made public.
BibTeX
@misc{alasmawi2026dino,
  author = {Hussain Alasmawi and Numan Saeed and Mohammad Yaqub},
  title = {{DINO-KNN: Training-Free Multiclass In-Context Segmentation via Nearest Neighbors}},
  year = {2026},
  eprint = {2611.28127},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.28127},
}
Figure