Maximizing Cosine Similarity Between Spatial Features for Unsupervised Domain Adaptation in Semantic Segmentation

Inseop Chung, Daesik Kim, Nojun Kwak

Abstract

This paper introduces a streamlined approach to Unsupervised Domain Adaptation (UDA) for semantic segmentation by replacing complex adversarial networks with a direct, feature-level alignment strategy. By maximizing the cosine similarity between target features and a class-wise dictionary of source features, the authors achieve state-of-the-art performance with significantly more stable training than traditional GAN-based methods. The proposed method preserves fine-grained spatial relationships and ensures consistent reference points through a memory-based dictionary, leading to cleaner segmentation masks on standard benchmarks like GTA5 and SYNTHIA to Cityscapes.

Introduction

Semantic segmentation—the task of assigning a class label to every pixel in an image—is notoriously data-hungry. While researchers can generate vast amounts of labeled data using synthetic environments like GTA5 or SYNTHIA, models trained on these "source" domains often fail when deployed in real-world "target" domains (such as Cityscapes) due to the significant domain gap.

Traditionally, researchers have relied on Adversarial Adaptation to bridge this gap. This involves training a discriminator to distinguish between source and target features while the segmentation network attempts to deceive it. However, this approach is often unstable, treats the domain gap as a simple binary classification problem, and frequently ignores the fine-grained spatial relationships between specific features. This paper proposes a more direct and stable alternative.

Proposed Method

The authors propose a novel Cosine Similarity Loss that operates directly at the feature level, bypassing the need for adversarial training. The architecture is designed to align target features with source features in a way that respects semantic categories and spatial details.

Overview of the proposed UDA architecture featuring the class-wise source feature dictionary and cosine similarity loss.

1. Spatial Feature Alignment

Instead of averaging features across a whole class—which often results in the loss of structural detail—the method flattens the feature maps and computes a comprehensive similarity matrix between every target feature and every source feature of the same class. This allows the model to preserve the structural nuances of the objects it is trying to segment.

The process of computing the cosine similarity matrix between flattened target and source feature maps, followed by thresholding and selection.

2. Selective Maximization

To avoid forcing unrelated features together, the model employs a thresholding mechanism ($T_{cos}$). It only maximizes similarity for pairs that already exceed this threshold, effectively "nudging" target features toward their most similar source counterparts rather than forcing alignment across disparate features.

3. Class-wise Source Feature Dictionary

A common issue in mini-batch training is the "unmatching problem," where a target image might contain a specific class (e.g., a bicycle) that is absent from the current source batch. To solve this, the authors maintain a dictionary (a queue) that stores the most recent source features for every class. This ensures the target always has a relevant reference point to learn from, regardless of the current batch composition.

Experimental Results

The researchers evaluated their method on two standard "Synthetic-to-Real" benchmarks for UDA: GTA5 → Cityscapes and SYNTHIA → Cityscapes.

Quantitative Performance

The method achieved impressive results across different network architectures:

  • GTA5 → Cityscapes: Using a DeepLabV2-ResNet101 backbone, the method reached 49.7% mIoU, outperforming most contemporary UDA methods. On the FCN-8s-VGG16 architecture, it set a new state-of-the-art at 44.3% mIoU.
  • Ablation Studies: Removing the dictionary or the class-wise split led to a clear drop in performance, validating that both the "memory" and the "semantic grouping" are essential for successful adaptation.

Qualitative Improvements

Visual results demonstrate that the model produces much "cleaner" and smoother segmentation masks compared to adversarial methods. GAN-based approaches often suffer from noisy predictions and misclassified segments (like road fragments appearing in buildings), whereas the cosine similarity approach maintains better spatial consistency.

Discussion and Insights

One of the most striking findings of this research is that adversarial training is not mandatory for effective domain adaptation. In fact, the authors found that adversarial loss was actually counterproductive when used alongside their method, as it disrupted the fine-grained feature alignment.

By using a direct similarity loss, the authors demonstrate a much smoother, consistently upward-trending mIoU during training compared to the "jittery" performance curves typical of GANs. The use of a feature dictionary (memory bank) is also vital, making the adaptation process much more robust to batch-to-batch variance.

Limitations and Future Work

While robust, the method introduces new hyperparameters, specifically the similarity threshold ($T_{cos}$) and the dictionary size, which require tuning based on the specific architecture. Additionally, the method relies on pseudo-labels (the model’s high-confidence predictions on the target domain). If the initial model is poor, the alignment might be guided by incorrect labels. Future work could explore combining this feature-level alignment with advanced style-transfer techniques to further reduce the initial domain gap.

Summary updated

BibTeX
@inproceedings{chung2022maximizing,
  author = {Inseop Chung and Daesik Kim and Nojun Kwak},
  title = {{Maximizing Cosine Similarity Between Spatial Features for Unsupervised Domain Adaptation in Semantic Segmentation}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2022},
  doi = {10.1109/wacv51458.2022.00204},
}
Figure