Domain Adaptation for Semantic Segmentation via Patch-Wise Contrastive Learning

Weizhe Liu, David Ferstl, Samuel Schulter, Lukas Zebedin, Pascal Fua, Christian LeistnerarXiv 2021

Abstract

Training semantic segmentation models requires extensive pixel-level annotations, which are costly to produce. While Unsupervised Domain Adaptation (UDA) leverages synthetic data, traditional adversarial methods often suffer from training instability. This paper proposes a novel framework using patch-wise contrastive learning to align feature distributions across domains. By utilizing a spatial pyramid matching metric in the label space, the method identifies semantically similar patches to guide feature alignment. The approach achieves state-of-the-art performance in both UDA and Semi-Supervised Domain Adaptation (SSDA) settings, demonstrating significant gains with minimal target-domain supervision.

Introduction

The performance of deep learning models in semantic segmentation is heavily dependent on the availability of large-scale, accurately labeled datasets. Creating such datasets for real-world environments, like urban driving scenes, is prohibitively expensive. Domain adaptation offers a solution by training models on synthetic data (e.g., GTA5) and adapting them to real-world target domains (e.g., Cityscapes).

Historically, UDA has relied on adversarial learning, where a discriminator attempts to distinguish between source and target features. However, these min-max optimization games are notoriously unstable. Furthermore, existing research often overlooks the practical scenario of Semi-Supervised Domain Adaptation (SSDA), where a small amount of target-domain labeling is available. This paper addresses these challenges by introducing a stable, contrastive learning-based alignment strategy.

Patch-Wise Contrastive Learning Framework

The proposed method replaces the standard adversarial discriminator with a contrastive loss applied to image patches. The core objective is to pull together the latent representations of patches with similar semantic layouts while pushing apart those that differ.

Overview of the patch-wise contrastive learning architecture for domain adaptation.

Semantic Disparity and Spatial Pyramid Matching

To identify positive and negative pairs for contrastive learning, the authors introduce a spatial pyramid matching metric. This metric operates in the label space (using ground truth for source and pseudo-labels for target) to compare the structural layout of patches. By calculating histograms of class labels at multiple resolution levels, the model captures both the global semantic content and the local spatial arrangement within each patch.

Architecture and Implementation

The framework utilizes a DeepLabV2 backbone with a ResNet101 encoder. Features from multiple layers are projected into a shared latent space via Multi-Layer Perceptrons (MLPs). Fourier Domain Adaptation (FDA) is employed as a preprocessing step to reduce low-level appearance differences by swapping low-frequency spectral components between domains.

Experimental Results

The method was evaluated on standard benchmarks, including GTA5 to Cityscapes and SYNTHIA to Cityscapes.

Performance in UDA and SSDA

In the purely unsupervised setting (UDA), the proposed method achieved 50.85 mIoU on GTA5 → Cityscapes, surpassing strong baselines like FDA. The advantages became even more pronounced in the SSDA setting. With only 50 annotated target images, the model reached 54.17 mIoU, significantly outperforming previous state-of-the-art methods. Increasing the supervision to 500 images further boosted performance to 60.43 mIoU.

Training Stability

One of the primary motivations for moving away from adversarial learning was training stability. As shown in the loss curves, the contrastive approach exhibits much smoother convergence compared to the volatile behavior of adversarial networks like AdvEnt.

Comparison of training stability between adversarial learning (AdvEnt) and the proposed contrastive approach.

Efficiency of Weak Supervision

The authors also explored "block-wise" annotation, where small 10x10 pixel blocks are labeled across many images. Results showed that annotating 25% of pixels across 200 images (55.94 mIoU) was more effective than fully annotating 50 images (54.17 mIoU), despite requiring similar total effort. This suggests that spreading annotation effort across more diverse scenes is a superior strategy for domain adaptation.

Conclusion

This research demonstrates that patch-wise contrastive learning is a robust and efficient alternative to adversarial methods for domain adaptation. By focusing on local semantic structures and leveraging even minimal target-domain supervision, the framework significantly bridges the gap between synthetic and real-world data. Future work involving active learning could further optimize the selection of patches for human annotation, making high-performance semantic segmentation even more accessible.

Summary updated

BibTeX
@misc{liu2021domain,
  author = {Weizhe Liu and David Ferstl and Samuel Schulter and Lukas Zebedin and Pascal Fua and Christian Leistner},
  title = {{Domain Adaptation for Semantic Segmentation via Patch-Wise Contrastive Learning}},
  year = {2021},
  eprint = {2104.11056},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.11056},
}
Figure