Probability Density from Latent Diffusion Models for Out-of-Distribution Detection

Joonas Järve, Karl Kaspar Haavel, Meelis KullarXiv 2025 · DOI

Introduction: The OOD Detection Paradox

Machine learning models often exhibit overconfidence when encountering data outside their training distribution (Out-of-Distribution, or OOD), posing significant safety risks for real-world deployment. Ideally, a generative model should assign high likelihood to In-Distribution (InD) data and low likelihood to OOD data. However, a well-known paradox exists: models trained on complex images (e.g., CIFAR-10) often assign higher likelihoods to simpler OOD data (e.g., MNIST). This failure is typically attributed to pixel-space models focusing on low-level statistics like local textures rather than high-level semantic content.

Methodology: Density Estimation in Latent Space

To address this, the researchers propose shifting density estimation from raw pixels to a high-level latent representation space. Their approach involves:

  1. Feature Extraction: Mapping images into a 512-dimensional space using a pre-trained ResNet-18 classifier.
  2. Latent Variational Diffusion Models (VDMs): Training a VDM specifically to model the distribution of these 512-D latent vectors.
  3. Exact Likelihood Calculation: Utilizing Probability-Flow ODEs to compute precise log-likelihoods, moving beyond the standard variational lower bounds typically provided by diffusion models.

The study evaluates three primary scoring metrics: Exact Likelihood (EL), Prior Likelihood (PL) (the likelihood of the vector after being diffused toward a Gaussian prior), and a novel Top-K Diffusion Loss (TKDL), which uses class-conditioned reconstruction error to determine how well a sample fits the learned manifold.

Key Insights: Why Latent Space Matters

A core finding of the paper is that density-based detection is theoretically optimal under certain assumptions, but its success is highly dependent on the coordinate system (space) used.

Effect of monotone transformations on probability density.

As illustrated above, monotone transformations can drastically alter density profiles. The authors argue that the failure of previous methods was not inherent to density estimation itself, but rather a consequence of working in pixel space. By moving to the latent space of a classifier, the model focuses on semantic features that better distinguish InD from OOD.

Furthermore, the Prior Likelihood (PL) was found to be particularly effective early in training. Because diffusion models learn coarse, robust features (the "noisy" levels) before fine-grained details, the prior space captures high-level structure more reliably than the exact pixel-level density.

Experimental Results

Evaluated on the OpenOOD benchmark, the VDM-based approach showed strong performance, particularly on CIFAR-10, matching or nearing specialized state-of-the-art methods like KNN and VIM.

Separation of In-Distribution and OOD log-likelihoods.

As shown in the histograms, both Exact Likelihood ($\log p_0(z)$) and Prior Likelihood ($\log p_T(z)$) provide clear separation between training/test data and OOD samples. In this instance, the prior likelihood achieves a higher AUROC of 0.885 compared to 0.869 for exact likelihood. The TKDL metric proved even more robust, reaching an AUROC of 0.8767 for Near-OOD and 0.9039 for Far-OOD on CIFAR-10.

Challenges and Limitations

While successful on CIFAR, the method faced challenges with ImageNet-200, likely due to the increased complexity of the 200-class distribution exceeding the VDM's current capacity. Additionally, the authors noted a sensitivity to overfitting: as the VDM continues to train, the likelihood gap between InD and OOD can diminish, highlighting the importance of early stopping or specific regularization techniques like spectral normalization.

Conclusion

By leveraging the representational power of pre-trained classifiers and the density estimation capabilities of Variational Diffusion Models, this work demonstrates that density-based OOD detection is a viable and competitive strategy when applied in the appropriate latent space. Future work will focus on scaling these models to handle more complex datasets and exploring more stable representation encoders.

Summary updated

BibTeX
@misc{jarve2025probability,
  author = {Joonas Järve and Karl Kaspar Haavel and Meelis Kull},
  title = {{Probability Density from Latent Diffusion Models for Out-of-Distribution Detection}},
  year = {2025},
  eprint = {2508.15737},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.15737},
}
Figure