Exploring Cross-Image Pixel Contrast for Semantic Segmentation

Wenguan Wang, Tianfei Zhou, Fisher Yu, Jifeng Dai, Ender Konukoglu, Luc Van Gool

Abstract

Traditional semantic segmentation models primarily rely on local context within individual images, often failing to capture global categorical relationships across the entire dataset. This paper proposes a supervised pixel-wise contrastive learning framework that explicitly models these relationships. By pulling embeddings of the same class closer and pushing different classes apart across multiple images, the method produces a more structured feature space. Evaluated on benchmarks like Cityscapes and COCO-Stuff, the approach yields significant performance improvements over state-of-the-art baselines without increasing inference latency.

Introduction

Standard semantic segmentation training typically employs a pixel-wise cross-entropy loss, which treats every pixel as an independent classification task. This approach focuses almost exclusively on local spatial dependencies—how a pixel relates to its neighbors within the same image. While effective, it ignores the broader global context of the training data. Ideally, a robust model should learn an embedding space where pixels of the same class (e.g., "car") are tightly clustered together, and pixels of different classes are well-separated, regardless of the specific image they appear in.

Methodology

The authors introduce a supervised pixel-wise contrastive algorithm that shifts the training paradigm from an image-centric view to a dataset-wide, pixel-to-pixel paradigm.

Conceptual overview of cross-image pixel contrast, showing how pixels from different images are mapped to a structured embedding space.

Pixel-to-Pixel Contrast

Using a modified InfoNCE loss, the model is trained to minimize the distance between an "anchor" pixel embedding and "positive" samples (pixels of the same class from any image in the training batch) while maximizing the distance to "negative" samples (pixels of different classes). This encourages intra-class compactness and inter-class dispersion.

Region Memory Bank and Hard Sampling

To manage the computational complexity of dataset-wide comparisons, the framework maintains a Region Memory Bank. This bank stores region-level features—the average embedding of all pixels of a specific class within an image—allowing for efficient "pixel-to-region" contrast. Furthermore, the authors employ Hard Example Sampling to focus the learning process on challenging cases, such as pixels the model is currently misclassifying (segmentation-aware hard anchor sampling).

Zero-Cost Inference

A small projection head (MLP) is used during training to map features into the contrastive space. Crucially, this head and the memory bank are discarded at inference time. Consequently, the performance gains are achieved with zero additional latency for the end-user.

Key Results

The proposed method was integrated into several state-of-the-art architectures, including DeepLabV3, HRNet, and OCR, across four major benchmarks: Cityscapes, PASCAL-Context, COCO-Stuff, and CamVid.

Comparison of accuracy (mIoU) vs. model size, demonstrating consistent gains across various baseline architectures.

On the Cityscapes dataset, adding the contrastive module to HRNetV2-W48 improved mIoU from 78.1% to 81.0% (+2.9%). Similar consistent gains were observed on PASCAL-Context (improving OCR from 56.2% to 57.2%) and COCO-Stuff (improving OCR from 40.5% to 41.0%). Visualization via t-SNE confirms that the method produces significantly cleaner and more separated clusters in the feature space compared to standard cross-entropy training.

Conclusion

By leveraging cross-image pixel contrast, this framework provides a stronger supervisory signal that helps models learn more robust, invariant features. The method is versatile, backbone-agnostic, and provides a significant boost to segmentation accuracy without any inference-time overhead. Future work may explore extending this global context paradigm to semi-supervised learning and other dense prediction tasks like pose estimation.

Summary updated

BibTeX
@inproceedings{wang2021exploring,
  author = {Wenguan Wang and Tianfei Zhou and Fisher Yu and Jifeng Dai and Ender Konukoglu and Luc Van Gool},
  title = {{Exploring Cross-Image Pixel Contrast for Semantic Segmentation}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  doi = {10.1109/iccv48922.2021.00721},
}
Figure