Near, far: Patch-ordering enhances vision foundation models' scene understanding

Valentinos Pariza, Mohammadreza Salehi, Gertjan Burghouts, Francesco Locatello, Yuki M. Asano

TL;DR

The paper introduces NeCo (Patch Neighbor Consistency), a self-supervised training loss that enhances the dense spatial representations of vision foundation models through patch-level nearest neighbor sorting. By acting as a lightweight "dense post-pretraining" stage, NeCo significantly improves scene understanding, semantic segmentation, and 3D consistency across various architectures, requiring only 19 hours of training on a single GPU.

What Problem Does This Paper Address?

While modern vision foundation models (like DINOv2 or iBOT) excel at image-level tasks, producing high-quality, dense, patch-level representations for complex scene understanding remains a challenge.

Existing dense self-supervised learning (SSL) methods typically rely on two paradigms, both of which have distinct drawbacks:

  1. Contrastive Learning: Relies on a binary "attract" or "repel" signal. This is too coarse to capture nuanced spatial relationships (e.g., a patch of a car tire should be highly similar to another tire patch, moderately similar to a car body, and completely distinct from an airplane).
  2. Reconstruction-based Methods (e.g., MAE): Focus heavily on low-level pixel similarities, which often fail to capture higher-level semantic meaning.

Furthermore, utilizing nearest-neighbor retrieval as a training mechanism is historically difficult because the sorting operation required to find neighbors is inherently discrete and non-differentiable, meaning it cannot propagate gradients during backpropagation.

Methods

NeCo overcomes these challenges by introducing an inverted approach: using nearest-neighbor retrieval not just for evaluation, but as a continuous training objective.

Figure 1: NeCo overview. Given an input image I, two augmentations τ1 and τ2 are applied to create two different views, which are processed by the teacher and student encoders, ϕt and ϕs respectively. The teacher encoder is updated using Exponential Moving Average (EMA). The encoded features are then aligned using ROI Align and compared with reference features Fr obtained by applying ϕt to other batch images. Next, pairwise distances Dij between Fs and Fr, as well as between Ft and Fr, are computed using cosine similarity. These distances are then sorted using differentiable sorting and utilized to force nearest order consistency across the views through the NeCo loss.

The core workflow consists of the following steps:

  • Student-Teacher Framework: The model processes two augmented views of an image through a student network and an Exponential Moving Average (EMA) teacher network.
  • Feature Alignment: Because different crops capture different parts of an image, ROI Align is used to spatially align the dense feature maps between the student and teacher.
  • Pairwise Distance & Reference Sampling: The model samples a random fraction of patch features from the entire batch to act as global reference patches. It then computes pairwise cosine similarity matrices between the aligned image patches and these reference patches.
  • Differentiable Sorting: To bypass the non-differentiable nature of standard sorting, the authors employ a relaxed, differentiable sorting algorithm (specifically, Bitonic Differentiable Sorting Networks). This converts the discrete ranking into continuous permutation matrices ($Q^s$ and $Q^t$), representing a probability distribution of neighbor orderings.
  • Consistency Loss: A cross-entropy loss enforces that the student's patch-neighbor ordering matches the teacher's patch-neighbor ordering, providing a rich, continuous learning signal.

Datasets

  • Training: Primarily optimized on COCO (scene-centric) and ablated on ImageNet-100 and Pascal VOC12.
  • Evaluation: Evaluated across a wide variety of downstream tasks using Pascal VOC12, COCO-Things, COCO-Stuff, ADE20K, Pascal Context, Cityscapes, NYUd (for depth prediction), Vaihingen, and SPair-71k (for 3D multi-view consistency).

Key Insights and Ideas

  • Sorting Over Binaries: Moving from binary contrastive signals to continuous ranking provides a much richer supervisory signal. Preserving the exact order of neighbors prevents mode collapse and retains subtle distinctions between different parts of the same object.
  • Deep Feature Space vs. Pixel Space: Operating strictly within the latent space of pretrained models ensures the network learns high-level semantics rather than superficial pixel-level similarities.
  • The Power of Post-Pretraining: Instead of training a massive dense model from scratch, NeCo demonstrates that you can "bootstrap" existing state-of-the-art models (like DINOv2 with registers) via a short, highly efficient post-pretraining phase.

Key Results

NeCo consistently establishes new state-of-the-art performance across multiple dense benchmarks:

  • Visual In-Context Learning: On non-parametric nearest-neighbor semantic segmentation, NeCo outperforms strong baselines like DINOv2R and CrIBo by 4% to 13% across different data fractions on Pascal VOC and ADE20K, showing exceptional data efficiency.
Figure 2: In-context scene understanding benchmark. Dense nearest neighbor retrieval perfor- mance is reported across various training data proportions on two scene-centric datasets, Pascal VOC and ADE20k. The retrieved cluster maps are compared with the ground truth using Hungarian matching (Kuang et al., 2021), and their mIoU score is reported. For all models, ViT-B16 is used except for DINOv2R and NeCo, where it is ViT-B14. For full tables, refer to Appendix B.3
  • Frozen Clustering Performance: In overclustering evaluations ($K=300$ and $K=500$), NeCo boosts DINOv2R's mIoU on Pascal VOC from 46.7% to 66.5%, proving that its features are significantly more discriminative and tightly bounded.
  • Linear & Full Finetuning: NeCo yields consistent gains in linear semantic segmentation (+1.6% on COCO-Things, +4.8% on COCO-Stuff) and sets a new state-of-the-art when paired with a Segmenter head.
  • 3D and Multi-View Understanding: On the SPair-71k geometric correspondence dataset, NeCo improves the multi-view feature consistency of DINO models by roughly 1.8% overall (and up to 10% in specific object categories), showing its utility extends well beyond 2D segmentation.
  • Broad Architecture Compatibility: The loss function successfully enhances not only standard vision transformers (DINO, iBOT, Leopart) but also vision-language foundation models like CLIP and SigLIP.

Limitations and Future Work

  • Small Object Sensitivity: Because the method relies on cropping to induce nearest neighbor similarity, very small objects in the background can occasionally alter patch-level semantics unexpectedly (e.g., mismatching a bicycle wheel patch with a motorcycle wheel patch).
  • Batch Size Scaling: Ablation studies show that NeCo's performance scales heavily with batch size. Smaller batch sizes yield marginal gains, implying that optimal performance requires significant hardware memory, though the authors note that performance could scale even further with batch sizes exceeding 64.

Summary updated

BibTeX
@inproceedings{pariza2025near,
  author = {Valentinos Pariza and Mohammadreza Salehi and Gertjan Burghouts and Francesco Locatello and Yuki M. Asano},
  title = {{Near, far: Patch-ordering enhances vision foundation models' scene understanding}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=Qro97zWC29},
}
Figure