Abstract
Out-of-Distribution (OOD) detection is a crucial problem for the safe deployment of machine learning models identifying samples that fall outside of the training distribution, i.e. in-distribution data (ID). Most OOD works focus on the classification models trained with Cross Entropy (CE) and attempt to fix its inherent issues. In this work we leverage powerful representation learned with Supervised Contrastive (SupCon) training and propose a holistic approach to learn a classifier robust to OOD data. We extend SupCon loss with two additional contrast terms. The first term pushes auxiliary OOD representations away from ID representations without imposing any constraints on similarities among auxiliary data. The second term pushes OOD features far from the existing class prototypes, while pushing ID representations closer to their corresponding class prototype. When auxiliary OOD data is not available, we propose feature mixing techniques to efficiently generate pseudo-OOD features. Our solution is simple and efficient and acts as a natural extension of the closed-set supervised contrastive representation learning. We compare against different OOD detection methods on the common benchmarks and show state-of-the-art results.
Introduction
Deep learning models typically operate under a "closed-set" assumption, where test-time data is expected to belong to the training categories. However, in real-world applications like autonomous driving, models frequently encounter Out-of-Distribution (OOD) data. Standard models trained with Cross-Entropy (CE) loss often exhibit dangerous overconfidence on such unknown samples. While many methods attempt to post-process CE-trained models, this paper argues that Supervised Contrastive Learning (SupCon) provides a more robust foundation for OOD detection by learning to cluster similar representations and separate dissimilar ones.
Methodology: OPSupCon
The proposed framework, OOD-aware Prototypical Supervised Contrastive Learning (OPSupCon), modifies the standard SupCon pipeline to explicitly account for the "unknown" space.
Prototypical Classifier and Tightness Loss
Instead of a linear classification layer, OPSupCon utilizes class prototypes in the embedding space. A Tightness Loss ($\mathcal{L}_E^P$) is introduced to force ID features to cluster tightly around their respective class prototypes, creating well-defined regions for known classes.
OOD Contrastive Terms
To handle OOD data, the framework introduces two additional loss terms:
- Encoder Level ($\mathcal{L}_E^O$): This term pushes OOD features away from all known class prototypes, ensuring they reside in the "no man's land" of the embedding space.
- Projection Head ($\mathcal{L}_H^O$): This term pushes OOD representations away from all ID representations, further regularizing the feature space.
Pseudo-OOD Generation
When real auxiliary OOD data is unavailable, the authors propose a feature-mixing technique. By mixing features from different ID classes (similar to Manifold Mixup), they generate "pseudo-OOD" samples that fall into the gaps between known categories, helping the model learn the boundaries of the ID distribution.
Experimental Results
The method was evaluated using CIFAR-10 and CIFAR-100 as In-Distribution (ID) datasets against a diverse set of OOD benchmarks, including DTD, SVHN, and Places365.
As shown in the results for CIFAR-10, OPSupCon-R (using real auxiliary OOD data) achieved an average False Positive Rate (FPR@95) of 12.01%, significantly outperforming the Cross-Entropy baseline (23.02%) and Energy-based fine-tuning (16.63%). Even the "Pseudo" version (OPSupCon-P), which does not require real OOD data during training, remained highly competitive with an average FPR of 13.52%. On the more complex CIFAR-100 dataset, OPSupCon-R reduced the average FPR to 50.97%, compared to 69.67% for standard CE.
Discussion and Limitations
A key insight of this work is that OOD data typically projects into the "gaps" between ID clusters. By explicitly regularizing these spaces using prototypes and contrastive terms, OPSupCon prevents class boundaries from over-extending into unknown regions.
However, the approach has limitations. Supervised Contrastive Learning requires significantly more training epochs (e.g., 500) compared to standard CE. Additionally, while pseudo-OOD generation is effective, the highest performance still relies on the availability of representative real auxiliary OOD data. Future research will focus on scaling this prototypical approach to larger datasets with thousands of classes.
Summary updated