Manuscript Offprint

arXiv:2609.01787

CoViT: Instance-Correspondence Contrastive Learning for Vision Transformer

Yisen Wang, Zhirong Wu, Limin Wang

Abstract

Vision Transformers (ViT) excel in semantic understanding but fail to discriminate between object instances (e.g., identical embeddings for two dogs), limiting their use in instance-level tasks such as object detection and instance segmentation. We propose Contrastive Vision Transformer (CoViT), a self-supervised learning framework that injects instance-awareness into ViT through geometry-guided contrastive learning. CoViT uniquely coordinates ViT's attention maps and embeddings by constructing triplets: (1) Attention-guided masking: Refine multi-head attention via adaptive thresholding and morphological operations to generate instance masks, identifying foreground anchors; (2) Hardest contrastive mining: For each anchor, computing pairwise embedding similarities to select the intra-instance hardest positive (least similar patch within its mask) and inter-instance hardest negative (most similar patch from other instances), with intra-instance regions masked during negative search. These triplets drive a contrastive loss that simultaneously compresses intra-instance variance and expands inter-instance margins, forcing ViT to discern subtle geometric and appearance differences between instances. CoViT consistently achieves stable performance gains of over 2 AP points across multiple instance-level perception tasks by using ViT as backbone architecture. Notably, CoViT requires no extra decoders or labels, demonstrating that a pure ViT can learn instance-aware representations via inherent attention priors and targeted contrastive constraints. Code and models will be released.

1 Introduction

Vision Transformers (ViT) [1] have emerged as cornerstones in modern computer vision, demonstrating exceptional capabilities in semantic understanding through pre-training paradigms such as DeiT [2], MAE [3], and DINO [4]. These methods excel at tasks requiring holistic scene interpretation, including image classification and semantic segmentation, by learning representations that emphasize semantic coherence across image regions. However, a critical gap remains unaddressed. ViT inherently lacks the ability to distinguish between individual instances of the same semantic category. For example, when there are multiple different instances with the same semantics in the image that the ViT needs to process, such as two dogs, the embedding output of the ViT will produce roughly the same representation. This limitation fundamentally restricts their utility in instance-centric applications like instance segmentation, where precise discrimination between objects is paramount.

The underlying issue stems from the semantic-driven nature of existing pre-training objectives. Methods like MAE prioritize reconstructing masked patches through global context aggregation, while DINO enforces consistency between augmented views of an image. Although effective for learning invariant semantic features, such strategies inadvertently suppress fine-grained instance-specific cues. Consequently, the self-attention mechanisms in ViTs tend to capture broad semantic

39th Conference on Neural Information Processing Systems (NeurIPS 2025).

relationships rather than delineating boundaries between adjacent instances. Even state-of-the-art models struggle to maintain intra-instance feature consistency while maximizing inter-instance disparity, leading to ambiguous embeddings that hinder downstream instance-level tasks.

To bridge this gap, we introduce Contrastive Vision Transformer (CoViT), a contrastive learning framework designed to endow pre-trained ViTs with instance discrimination capabilities without architectural modifications. Our approach is grounded in two pivotal observations. First, thresholded and morphologically refined attention maps, despite their imperfections, provide spatial cues that approximate instance regions. Second, analyzing embedding similarities reveals systematic errors: embeddings of distinct instances often exhibit unexpectedly high similarity, while patches within the same instance may show undesirably low similarity. Leveraging these insights, CoViT constructs informative triplets by identifying intra-instance hard positives (regions within the same instance with minimal similarity to the anchor) and inter-instance hard negatives (regions from different instances with maximal similarity to the anchor). These triplets are derived through a synergistic analysis of attention maps and embedding similarities, enabling targeted contrastive optimization.

The CoViT framework imposes dual objectives: reducing feature distance between anchors and their intra-instance hard positives to enhance instance cohesion, while increasing the margin between anchors and inter-instance hard negatives to mitigate cross-instance confusion. This strategy directly addresses the limitations of conventional contrastive learning, which typically operates on image-level or patch-level pairs without explicit instance guidance. Experiments demonstrate that CoViT significantly enhances the instance awareness of pre-trained ViTs. When applied to DINO-Base, our method improves mask AP on COCO instance segmentation by 3.2% and boosts few-shot instance recognition accuracy on PASCAL VOC by 12.7%, all while preserving the model's original semantic representation strength.

Our work makes three core contributions. First, we systematically identify and analyze the inability of semantic-focused ViTs to discriminate instances, linking this limitation to the objectives of mainstream pre-training paradigms. Second, we propose CoViT, a novel framework that jointly exploits attention maps and embedding similarities to mine instance-aware triplets for contrastive fine-tuning. Third, we empirically validate CoViT's versatility across multiple instance-level tasks and ViT architectures, providing insights into the interplay between semantic and instance-level feature learning. By reconciling the semantic richness of pre-trained ViTs with instance-sensitive adaptation, this work opens new avenues for deploying ViTs in scenarios requiring precise instance discrimination.

References (33)