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

Inseop Chung, Daesik Kim, Nojun Kwak

Abstract

Unsupervised Domain Adaptation (UDA) for semantic segmentation typically relies on adversarial training to bridge the gap between synthetic source data and real-world target data. However, adversarial methods are often unstable and fail to capture fine-grained spatial details. This paper introduces a novel approach that maximizes the cosine similarity between spatial features of the source and target domains. By incorporating a class-wise source feature dictionary, the method ensures robust alignment even when specific classes are absent from individual training images. Evaluations on GTA5 and SYNTHIA benchmarks show that this approach achieves state-of-the-art performance, producing cleaner and more consistent segmentation maps than traditional adversarial techniques.

Introduction

Semantic segmentation—the task of pixel-level classification—requires vast amounts of labeled data. While synthetic environments like GTA5 provide an easy source of labels, models trained on them often struggle with the "domain gap" when applied to real-world datasets like Cityscapes. Current UDA solutions predominantly use adversarial adaptation, where a discriminator attempts to distinguish between source and target feature maps. Despite their popularity, these methods are notoriously difficult to stabilize and often overlook local spatial consistency.

Methodology

The proposed framework shifts the focus from global adversarial competition to direct feature-level metric learning. The core hypothesis is that features representing the same semantic class should exhibit high cosine similarity regardless of their domain of origin.

Cosine Similarity Maximization

The model computes a similarity matrix between flattened source and target feature maps. To avoid noisy gradients, a thresholding mechanism is applied: only target features that already show moderate similarity to source features are pushed toward a similarity of 1.0. This selective optimization prevents the model from incorrectly aligning disparate classes.

Class-wise Source Feature Dictionary

A significant hurdle in direct feature alignment is the "unmatching problem," where a target image may contain classes not present in the current source batch. To mitigate this, the authors implement a class-wise dictionary maintained as a queue. This dictionary stores a diverse history of source features for every class, allowing the model to compare a target pixel (e.g., a "bus") against a representative set of source "bus" features collected over multiple iterations.

Overview of the proposed framework featuring the class-wise source feature dictionary.

Notably, the researchers found that adversarial loss was not only unnecessary but actually detrimental when combined with this spatial alignment strategy. Consequently, the final model is trained using only standard segmentation loss and the proposed cosine similarity loss.

Experimental Results

The method was evaluated on standard UDA benchmarks: GTA5 → Cityscapes and SYNTHIA → Cityscapes.

Quantitative Performance

Using a ResNet101 backbone, the proposed method achieved a state-of-the-art 49.7% mIoU on the GTA5 → Cityscapes task. This performance surpasses several complex models that rely on adversarial training or image-level style transfer. Peak performance is achieved when the method is combined with self-supervised learning using pseudo-labels, though the quality of the initial model remains a critical factor.

Qualitative Analysis

Qualitative evaluations reveal that the cosine similarity approach produces significantly cleaner segmentation maps. Adversarial models frequently suffer from "noisy" predictions, such as misclassifying road segments as sidewalks. In contrast, the proposed method maintains high spatial consistency and excels at recognizing small, distant objects like pedestrians.

Qualitative comparison of semantic segmentation results.

Conclusion

By replacing unstable adversarial training with direct spatial feature alignment, this work provides a robust and effective alternative for Unsupervised Domain Adaptation. The use of a class-wise dictionary effectively addresses the class-mismatch problem, leading to superior performance on real-world autonomous driving datasets. While the method shows sensitivity to hyperparameters like the similarity threshold and dictionary size, its ability to produce spatially precise predictions marks a significant step forward in UDA for semantic segmentation.

Reference: Chung, I., Kim, D., & Kwak, N. (2021). Maximizing Cosine Similarity Between Spatial Features for Unsupervised Domain Adaptation in Semantic Segmentation. arXiv:2102.13002v3.

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