Table of Contents
Fetching ...

FlowCon: Out-of-Distribution Detection using Flow-Based Contrastive Learning

Saandeep Aathreya, Shaun Canavan

TL;DR

FlowCon tackles OOD detection by marrying normalizing flows with a supervised contrastive loss to learn class-conditioned densities on penultimate classifier features. The core idea is to maximize the flow-based likelihood while a Bhattacharyya-inspired contrastive loss enforces tight, class-specific clusters, yielding robust in-distribution coverage and clear separation from out-of-distribution samples. The approach trains a single flow model on fixed classifier features, avoiding retraining or external OOD data, and computes OOD scores from per-class density estimates, achieving strong performance across far-OOD, near-OOD, and mixed scenarios on CIFAR-10/100 with ResNet18 and WideResNet backbones. Empirical results, likelihood histograms, and UMAP visualizations demonstrate FlowCon’s discriminative density structure, class-preserving behavior, and practical viability for real-world deployment in vision tasks.

Abstract

Identifying Out-of-distribution (OOD) data is becoming increasingly critical as the real-world applications of deep learning methods expand. Post-hoc methods modify softmax scores fine-tuned on outlier data or leverage intermediate feature layers to identify distinctive patterns between In-Distribution (ID) and OOD samples. Other methods focus on employing diverse OOD samples to learn discrepancies between ID and OOD. These techniques, however, are typically dependent on the quality of the outlier samples assumed. Density-based methods explicitly model class-conditioned distributions but this requires long training time or retraining the classifier. To tackle these issues, we introduce \textit{FlowCon}, a new density-based OOD detection technique. Our main innovation lies in efficiently combining the properties of normalizing flow with supervised contrastive learning, ensuring robust representation learning with tractable density estimation. Empirical evaluation shows the enhanced performance of our method across common vision datasets such as CIFAR-10 and CIFAR-100 pretrained on ResNet18 and WideResNet classifiers. We also perform quantitative analysis using likelihood plots and qualitative visualization using UMAP embeddings and demonstrate the robustness of the proposed method under various OOD contexts. Code will be open-sourced post decision.

FlowCon: Out-of-Distribution Detection using Flow-Based Contrastive Learning

TL;DR

FlowCon tackles OOD detection by marrying normalizing flows with a supervised contrastive loss to learn class-conditioned densities on penultimate classifier features. The core idea is to maximize the flow-based likelihood while a Bhattacharyya-inspired contrastive loss enforces tight, class-specific clusters, yielding robust in-distribution coverage and clear separation from out-of-distribution samples. The approach trains a single flow model on fixed classifier features, avoiding retraining or external OOD data, and computes OOD scores from per-class density estimates, achieving strong performance across far-OOD, near-OOD, and mixed scenarios on CIFAR-10/100 with ResNet18 and WideResNet backbones. Empirical results, likelihood histograms, and UMAP visualizations demonstrate FlowCon’s discriminative density structure, class-preserving behavior, and practical viability for real-world deployment in vision tasks.

Abstract

Identifying Out-of-distribution (OOD) data is becoming increasingly critical as the real-world applications of deep learning methods expand. Post-hoc methods modify softmax scores fine-tuned on outlier data or leverage intermediate feature layers to identify distinctive patterns between In-Distribution (ID) and OOD samples. Other methods focus on employing diverse OOD samples to learn discrepancies between ID and OOD. These techniques, however, are typically dependent on the quality of the outlier samples assumed. Density-based methods explicitly model class-conditioned distributions but this requires long training time or retraining the classifier. To tackle these issues, we introduce \textit{FlowCon}, a new density-based OOD detection technique. Our main innovation lies in efficiently combining the properties of normalizing flow with supervised contrastive learning, ensuring robust representation learning with tractable density estimation. Empirical evaluation shows the enhanced performance of our method across common vision datasets such as CIFAR-10 and CIFAR-100 pretrained on ResNet18 and WideResNet classifiers. We also perform quantitative analysis using likelihood plots and qualitative visualization using UMAP embeddings and demonstrate the robustness of the proposed method under various OOD contexts. Code will be open-sourced post decision.
Paper Structure (26 sections, 7 equations, 10 figures, 5 tables)

This paper contains 26 sections, 7 equations, 10 figures, 5 tables.

Figures (10)

  • Figure 1: Intuition behind FlowCon on toy moons dataset with OOD samples. Normalizing flows trained without contrastive loss ($\mathcal{L}_{flow}$ only) does not account for the class-specific information in the dataset and transforms the data into a unimodal Gaussian distribution as latent space, $z$. Flow model trained with $\mathcal{L}_{flow} + \mathcal{L}_{con}$ is able to learn class-specific multimodal Gaussian distributions. Consequently, when plotted against $\log p(z)$ using heatmaps, the unimodal Gaussian cluster does not account for OOD samples and assigns high likelihood irrespective of samples it was trained on. Conversely, optimizing $\mathcal{L}_{flow} + \mathcal{L}_{con}$ pushes ID data into the high density region and OOD samples into the low density region.
  • Figure 2: Training pipeline of FlowCon. Given an input image, $x$, the pretrained classifier first extracts deep features, $z_{emb}$. The flow model then operates on $z_{emb}$ to obtain the latent vector $z_{flow}$, and its corresponding distribution, $\mathcal{N}(\mu, \sigma)$. The loss $\mathcal{L}_{flow}$ maximizes the likelihood of $z_{flow}$ on $\mathcal{N}(\mu, \sigma)$, and simultaneously, $\mathcal{L}_{con}$ ensures high inter-class separability and low intra-class separability among the distribution $\mathcal{N}(\mu, \sigma)$ in a contrastive fashion.
  • Figure 3: $D_{in}=$ CIFAR-10. Top row represent Far-OOD where $D_{ood}$ is external OOD dataset. Bottom row indicates Mixed-OOD where $D_{ood}$ is CIFAR-100.
  • Figure 4: $D_{in}=$ CIFAR-100. Top row represent Far-OOD where $D_{ood}$ is external OOD dataset. Bottom row indicates Near-OOD where $D_{ood}$ is CIFAR-10.
  • Figure : ResNet18
  • ...and 5 more figures