Abstract
Collecting labeled data for the task of semantic segmentation is expensive and time-consuming, as it requires dense pixel-level annotations. While recent Convolutional Neural Network (CNN) based semantic segmentation approaches have achieved impressive results by using large amounts of labeled training data, their performance drops significantly as the amount of labeled data decreases. This happens because deep CNNs trained with the de facto cross-entropy loss can easily overfit to small amounts of labeled data. To address this issue, we propose a simple and effective contrastive learning-based training strategy in which we first pretrain the network using a pixel-wise, label-based contrastive loss, and then fine-tune it using the cross-entropy loss. This approach increases intra-class compactness and inter-class separability, thereby resulting in a better pixel classifier. Our results show that pretraining with the proposed contrastive loss results in large performance gains (more than 20% absolute improvement in some settings) when the amount of labeled data is limited. In many settings, the proposed contrastive pretraining strategy is able to match or outperform the widely-used ImageNet pretraining strategy without using any additional data.
Introduction
Semantic segmentation—the task of assigning a category to every single pixel in an image—is one of the most data-intensive tasks in computer vision. For instance, labeling a single image from the Cityscapes dataset requires an average of 90 minutes of manual effort. While deep learning has revolutionized this field, standard models rely on massive datasets to generalize. When training data is scarce, performance typically craters due to overfitting.
The primary culprit is the standard cross-entropy loss. While effective for large-scale training, cross-entropy focuses on finding decision boundaries without explicitly organizing the feature space. It fails to encourage "intra-class compactness" (ensuring pixels of the same class have similar features) or "inter-class separability" (pushing different classes apart). On small datasets, the model often learns the specific noise of the training samples rather than robust, generalizable features.
Proposed Method: Two-Stage Contrastive Learning
To overcome the limitations of cross-entropy in low-data regimes, we propose a two-stage training pipeline that uses available labels more efficiently.
1. Contrastive Pretraining
In the first stage, the CNN feature extractor is trained using a supervised, pixel-wise contrastive loss. This loss acts as a magnet: it pulls features of pixels belonging to the same class together and pushes pixels of different classes apart. We explored two primary variations:
- Within-image: Comparing pixels within the same image and its distorted versions.
- Cross-image: Pairing pixels from different images within a minibatch to provide more challenging positive and negative examples.
2. Softmax Fine-tuning
Once the feature space is well-organized into distinct clusters, we discard the contrastive projection head and add a standard softmax classifier. The entire network is then fine-tuned using traditional cross-entropy loss. This two-stage approach provides a cleaner initialization, preventing the model from getting stuck in poor local minima during the final classification phase.
Experimental Evaluation
We evaluated our method on two benchmarks: Cityscapes (urban street scenes) and PASCAL VOC 2012 (diverse objects). To test label efficiency, we trained models on varying subsets of these datasets, ranging from the full set down to approximately 1/10th of the available labels.
Key Results and Insights
The performance gains are most striking when data is scarcest. On the PASCAL VOC dataset with 2,118 images, standard training achieved a mean Intersection Over Union (mIOU) of 39.1%. Our contrastive strategy boosted this to 62.7%—a massive 23.6% absolute improvement.
Furthermore, our method demonstrates significant "label reduction" capabilities. On PASCAL VOC, a model trained with our strategy on just 1,059 images outperformed a standard model trained on 5,295 images. This represents a 5x reduction in the labeling effort required to reach a specific performance threshold. Notably, our method often matches or exceeds the performance of models pretrained on the million-image ImageNet dataset, despite using only the limited labels from the target task.
Conclusion
By explicitly optimizing the topology of the feature space before classification, supervised contrastive pretraining dramatically improves the label efficiency of semantic segmentation. This approach is particularly valuable for specialized domains where large-scale external datasets like ImageNet are unavailable or irrelevant. Future work will explore combining this supervised strategy with semi-supervised learning to further reduce the reliance on expensive pixel-level annotations.
Summary updated