Manuscript Offprint

arXiv:2608.22679

Contextrast++: Robust Multi-Scale Contextual Contrastive Learning for Semantic Segmentation

Changki Sung, Hyungtae Lim, Wanhee Kim, Youngwoo Seo, Hyun Myung

Changki Sung 1†^{1\dagger}, Hyungtae Lim 2†^{2\dagger}, Wanhee Kim 3^{3}, Youngwoo Seo 4^{4}, and Hyun Myung 5∗^{5*}, Senior Member, IEEE

Abstract—Semantic segmentation has rapidly advanced with deep learning; however, challenges remain in effectively capturing local and global contexts as well as addressing the long-tailed distribution problem. To tackle these issues, we present Contextrast++, a robust contrastive learning method for semantic segmentation that improves multi-scale feature integration and mitigates class imbalance issues. Our method consists of two key components: 1) contextual contrastive learning (CCL) and 2) boundary-aware negative (BANE) sampling. CCL includes three subcomponents: adaptive fusion module, pixel-to-anchor (PA) loss, and anchor-to-anchor (AA) loss. The adaptive fusion module dynamically balances local and global feature integration, resulting in a more context-aware representation. While the PA loss leverages the fused multi-scale features to improve feature representation learning, the AA loss focuses on addressing the long-tailed distribution problem by utilizing a memory bank that stores a fixed number of class-balanced representative anchors. Meanwhile, BANE sampling enhances segmentation precision by selecting hard negatives from misclassified boundary regions, which refines fine-grained details during contrastive learning. As verified in extensive experiments using public datasets, we demonstrate that Contextrast++ substantially improves semantic segmentation performance over existing contrastive learning-based state-of-the-art approaches, while introducing no additional computational overhead during inference.

Index Terms—Semantic segmentation, contrastive learning, representation learning.

I. INTRODUCTION

Semantic segmentation, a fundamental task in computer vision, plays a vital role in applications such as autonomous driving and robotics [1]–[11]. Recent advancements in deep learning, driven by the availability of extensive datasets [12]–[17], have boosted segmentation performance. Researchers

© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works. DOI: 10.1109/TPAMI.2026.3721845

*Corresponding author: Hyun Myung

†^{\dagger}These authors contributed equally to this work.

1^{1}Changki Sung is with the Information & Electronics Research Institute, KAIST, Daejeon, 34141, Republic of Korea. cs1032@kaist.ac.kr

2^{2}Hyungtae Lim is with Zoox Inc., Foster City, CA 94404, USA. hlim@zoox.com. This work was conducted in personal time and independently of the author's organization.

3^{3}Wanhee Kim is with the Robotics Program, KAIST (Korea Advanced Institute of Science and Technology), Daejeon, 34141, Republic of Korea. gml78905@kaist.ac.kr

4^{4}Youngwoo Seo is with Hanwha Aerospace, Pangyo, Gyeonggi-do, 13488, Republic of Korea. youngwoo.seo@hanwha.com

5^{5}Hyun Myung is with the School of Electrical Engineering, KAIST, Daejeon, 34141, Republic of Korea. hmyung@kaist.ac.kr

A preliminary version of this work has appeared in CVPR 2024 https://doi.org/10.1109/CVPR52733.2024.00358

Figure

(a) Ground truth

(b) HRNet [27]

(c) Ours

Embedding spaces Rd\mathbb{R}^{d}

Corresponding to the depth of layers

Figure

Anchor Updated anchor ⊕Vector/scalar aggregation

→ Pulling towards the anchor of each class

→ Pushing each other class based on our BANE sampling

Memory bank

Semantic

segmentation

network

(d)

Figure

On the embedding vector space Rd\mathbb{R}^{d}

For the class bus (●)

(e)

Fig. 1. Visualization of (a) ground truth annotations, (b) results obtained from HRNet [27], and (c) output after being trained with our contrastive learning approach. (d) Overview of the proposed contextual contrastive learning framework, referred to as Contextrast++, which refines class-specific anchors by aggregating the deepest-layer embeddings into earlier layers to enhance semantic and fine-grained feature representation. (e) Illustration of boundary-aware negative (BANE) sampling strategy, which selects feature embeddings near object boundaries (solid red triangles) as harder negative samples. This helps contrastive learning focus more on boundary regions, improving boundary prediction accuracy.

have introduced larger deep neural networks [18]–[51] and novel loss functions [52]–[54] to further improve segmentation accuracy.

Despite recent advancements, some semantic segmentation models still produce inaccurate results, as illustrated in Fig. 1(b). More specifically, semantic segmentation models continue to face challenges in accurately predicting small objects, object boundaries, and underrepresented (or long-tailed) classes. While increasing model complexity [55]–[57] can help mitigate these challenges, it results in higher memory consumption and slower inference speeds, which are critical drawbacks for autonomous driving and robotics. This underscores the need for efficient performance enhancements that do not require additional computational cost during inference.

To address the challenges of inaccurate predictions in small objects, boundaries, and underrepresented classes, as well as the high computational cost associated with complex models, contrastive learning-based methods [58]−[62][58]-[62] have emerged as an effective approach. Contrastive learning is applied exclusively during training, so semantic segmentation models retain identical memory consumption and processing time during inference. Consequently, contrastive learning offers a highly efficient solution for scenarios where low computational overhead and fast inference are essential.

However, existing contrastive learning methods for semantic segmentation either overlook multi-scale feature integration [58]−[60][58]-[60] or rely on separate multi-scale and cross-scale processes that cause inconsistent feature relationships [61][61] . Our previous work, Contextrast [62][62] , addressed this through fused representative anchors across scales, but had two limitations: (1) static weighted fusion lacks adaptability for diverse contexts, and (2) class imbalance within mini-batches leads to insufficient long-tailed distribution handling, where underrepresented classes have limited training instances.

Therefore, in this paper, we propose Contextrast++ to address these limitations. First, Contextrast++ introduces a lightweight adaptive fusion module that replaces the static weighted sum with a learnable mechanism, using self-attention, concatenation, and multi-layer perceptron (MLP) to adaptively integrate multi-scale anchors. This generates expressive class-specific feature vectors that enable the enhanced pixel-to-anchor (PA) loss to learn more consistent global-local representations.

Second, Contextrast++ introduces an anchor-to-anchor (AA) loss with a memory bank that stores class-balanced representative anchors. Unlike existing methods [58], [60] that store pixel-level features leading to imbalance, our anchor selection strategy extracts one anchor per class from the deepest layer when the class is present, storing only refined-then-fused class-level anchors. This enables class-balanced learning, effectively mitigating the long-tailed distribution problem.

In summary, this paper presents the following contributions:

  • Contextrast++ introduces a lightweight adaptive fusion module that replaces static weighting with learnable integration via self-attention and MLP, enabling adaptively fused representative anchors that enhance both PA loss and AA loss.

  • We introduce an efficient memory bank design that stores class-balanced representative anchors across all classes, enhancing the AA loss to effectively mitigate the long-tailed distribution problem.

  • Contextrast++ outperforms prior contrastive learning approaches across a range of CNN architectures [19], [27], [30] and transformer architectures [34], [63], evaluated on diverse datasets [13]–[17].

TABLE I COMPARISON OF CORE COMPONENTS BETWEEN OUR METHOD AND EXISTING STATE-OF-THE-ART APPROACHES. CL: CONTRASTIVE LEARNING, MB: MEMORY BANK, AL: AUXILIARY LOSS, SYN: SYNTHETIC NEGATIVE SAMPLE GENERATION.

MethodComponentsScaleBoundary awareness
Baseline---
Wang et al. ICCV 21 [58]CL, MBSingle✕
Hu et al. ICCV 21 [59]CL, MB, ALSingle✕
Pissas et al. ECCV 22 [61]CLMulti✕
Zhou et al. TPAMI 24 [60]CL, MB, SYNSingle✕
Sung et al. CVPR 24 [62]CLMulti-fusion (static)✓
OursCL, MBMulti-fusion (adaptive)✓

References (86)

  • FCN-transformer feature fusion for polyp segmentation
  • Semantic scene segmentation for robotics
  • Semantic scene segmentation for robotics applications
  • LCFNets: Compensation strategy for real-time semantic segmentation of autonomous driving
  • Robust 3D semantic segmentation based on multi-phase multi-modal fusion for intelligent vehicles
  • Segmentation of road negative obstacles based on dual semantic-feature complementary fusion for autonomous driving
  • CLFT: camera-LiDAR fusion transformer for semantic segmentation in autonomous driving (opens arXiv in a new tab)
  • S $^{3}$M-Net: joint learning of semantic segmentation and stereo matching for autonomous driving
  • Multi-branch differential bidirectional fusion network for RGB-T semantic segmentation
  • MLFNet: Multilevel fusion network for real-time semantic segmentation of autonomous driving
  • Multi-objective neural architecture search for efficient and fast semantic segmentation on edge
  • ImageNet: A large-scale hierarchical image database
  • The Cityscapes dataset for semantic urban scene understanding
  • The role of context for object detection and semantic segmentation in the wild
  • COCO-stuff: Thing and stuff classes in context
  • Semantic object classes in video: A high-definition ground truth database
  • Scene parsing through ADE20K dataset
  • DeepLab: Semantic image segmentation with deep convolutional nets, atrous convolution, and fully connected CRFs
  • Rethinking atrous convolution for semantic image segmentation (opens arXiv in a new tab)
  • Pyramid scene parsing network
  • Encoder-decoder with atrous separable convolution for semantic image segmentation
  • Unified perceptual parsing for scene understanding
  • Pyramid attention network for semantic segmentation (opens arXiv in a new tab)
  • Adaptive affinity fields for semantic segmentation
  • Learning a discriminative feature network for semantic segmentation
  • Semantic segmentation with extended DeepLabv3 architecture
  • High-resolution representations for labeling pixels and regions (opens arXiv in a new tab)
  • Dual attention network for scene segmentation
  • Context prior for scene segmentation
  • Object-contextual representations for semantic segmentation
  • Cars can’t fly up in the sky: Improving urban-scene segmentation via height-driven attention networks
  • Deep dual-resolution networks for real-time and accurate semantic segmentation of road scenes (opens arXiv in a new tab)
  • Progressive semantic segmentation
  • Swin Transformer: Hierarchical vision transformer using shifted windows
  • Understanding imbalanced semantic segmentation through neural collapse
  • InvPT++: Inverted pyramid multi-task transformer for visual scene understanding
  • MCTformer+: Multi-class token transformer for weakly supervised semantic segmentation
  • Object-centric representation learning for video scene understanding
  • Frequency-aware feature fusion for dense image prediction
  • Prototype-based semantic segmentation
  • Causal intervention for weakly-supervised semantic segmentation
  • Hierarchical feature alignment network for unsupervised video object segmentation
  • Multi-granularity denoising and bidirectional alignment for weakly supervised semantic segmentation
  • Self-regulation for semantic segmentation
  • Spatial structure constraints for weakly supervised semantic segmentation
  • CTNet: Context-based tandem network for semantic segmentation
  • Weakly-supervised dual clustering for image semantic segmentation
  • Merging context clustering with visual state space models for medical image segmentation
  • SegMAN: Omni-scale context modeling with state space models and local attention for semantic segmentation
  • LLMFormer: Large language model for open-vocabulary semantic segmentation
  • M-SEE: A multi-scale encoder enhancement framework for end-to-end weakly supervised semantic segmentation
  • SegFix: Model-agnostic boundary refinement for segmentation
  • Active boundary loss for semantic segmentation
  • Semantic diffusion network for semantic segmentation
  • Segmenter: Transformer for semantic segmentation
  • Deep hierarchical semantic segmentation
  • ConvNext v2: Co-designing and scaling ConvNets with masked autoencoders
  • Exploring cross-image pixel contrast for semantic segmentation
  • Region-aware contrastive learning for semantic segmentation
  • Cross-image pixel contrasting for semantic segmentation
  • Multi-scale and cross-scale contrastive learning for semantic segmentation
  • Contextrast: Contextual contrastive learning for semantic segmentation
  • Masked-attention mask transformer for universal image segmentation
  • Fully convolutional networks for semantic segmentation
  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Segformer: Simple and efficient design for semantic segmentation with transformers
  • Boundary-guided lightweight semantic segmentation with multi-scale semantic context
  • Multi-scale high-resolution vision transformer for semantic segmentation
  • Transformer scale gate for semantic segmentation
  • Targeted supervised contrastive learning for long-tailed recognition
  • Attention is all you need
  • Noise-contrastive estimation: A new estimation principle for unnormalized statistical models
  • Representation Learning with Contrastive Predictive Coding
  • Momentum contrast for unsupervised visual representation learning
  • Supervised contrastive learning
  • Hard negative mixing for contrastive learning
  • Sub-pixel distance maps and weighted distance transforms
  • MobileNetV2: Inverted residuals and linear bottlenecks
  • MMSegmentation: OpenMMLab semantic segmentation toolbox and benchmark
  • A stochastic estimator of the trace of the influence matrix for laplacian smoothing splines
  • An estimator for the diagonal of a matrix
  • FaceNet: A unified embedding for face recognition and clustering
  • Delving into inter-image invariance for unsupervised visual representations
  • Are all negatives created equal in contrastive instance discrimination? (opens arXiv in a new tab)
  • Hard negative examples are hard, but useful
  • Grad-CAM: Visual explanations from deep networks via gradient-based localization