Leveraging diffusion models for unsupervised out-of-distribution detection on image manifold

Zhenzhen Liu, Jin Peng Zhou, Kilian Q. WeinbergerFrontiers Artif. Intell 2024

Abstract

Out-of-distribution (OOD) detection is crucial for enhancing the reliability of machine learning models when confronted with data that differ from their training distribution. In the image domain, we hypothesize that images inhabit manifolds defined by latent properties such as color, position, and shape. Leveraging this intuition, we propose a novel approach to OOD detection using a diffusion model to discern images that deviate from the in-domain distribution. Our method involves training a diffusion model using in-domain images. At inference time, we lift an image from its original manifold using a masking process, and then apply a diffusion model to map it towards the in-domain manifold. We measure the distance between the original and mapped images, and identify those with a large distance as OOD. Our experiments encompass comprehensive evaluation across various datasets characterized by differences in color, semantics, and resolution. Our method demonstrates strong and consistent performance in detecting OOD images across the tested datasets, highlighting its effectiveness in handling images with diverse characteristics. Additionally, ablation studies confirm the significant contribution of each component in our framework to the overall performance.

Introduction

Machine learning models often exhibit overconfidence when presented with data outside their training distribution. This failure to recognize "out-of-distribution" (OOD) data can lead to deceptive results, posing significant safety risks in critical applications like healthcare or autonomous driving. Traditional OOD detection methods frequently rely on supervised learning—requiring examples of OOD data—or likelihood-based approaches. However, likelihood-based methods are prone to failure; for instance, models trained on complex datasets like CIFAR-10 often assign higher likelihoods to simpler, unrelated images like SVHN digits.

To address these limitations, researchers at Cornell University have introduced LMD (Lift, Map, Detect), an unsupervised framework that leverages the geometric structure of data manifolds.

The LMD Framework: Lift, Map, Detect

The core intuition behind LMD is that images from a specific domain reside on a low-dimensional manifold. By corrupting an image and attempting to reconstruct it using a model trained only on the in-domain manifold, we can determine its membership based on reconstruction fidelity.

The LMD framework: An image is lifted from its manifold via masking, mapped back using a diffusion model, and evaluated based on the distance from the original.

The process consists of three primary steps:

  1. Lift: The image is "lifted" from its original manifold through corruption. The authors utilize an 8x8 alternating checkerboard mask that obscures 50% of the pixels, effectively breaking the image's semantic structure.
  2. Map: A Diffusion Model (DM), trained exclusively on in-distribution (ID) data, performs inpainting on the masked image. Because the DM is only familiar with the ID manifold, it attempts to "pull" the input back toward that distribution. For ID images, the reconstruction is faithful; for OOD images, the DM struggles to reconcile the context, resulting in a "noisy" or semantically inconsistent output.
  3. Detect: The distance between the original and reconstructed image is measured using LPIPS (Learned Perceptual Image Patch Similarity). Unlike pixel-wise metrics like MSE, LPIPS utilizes deep features, making it highly sensitive to semantic discrepancies. To mitigate the stochastic nature of diffusion, the final OOD score is the median distance across multiple reconstructions.

Experimental Evaluation

The LMD framework was evaluated across 12 pairwise dataset combinations, ranging from small-scale benchmarks (CIFAR-10, SVHN, MNIST) to high-resolution datasets (CelebA-HQ, LSUN Bedroom).

LMD achieved state-of-the-art performance with an average ROC-AUC of 0.907, outperforming seven established baselines by an average of 9%. Notably, LMD excelled on the challenging CIFAR-100 vs. SVHN task, surpassing the best baseline by 10%. The method demonstrated remarkable robustness across diverse image types—including digits, objects, and scenes—without requiring dataset-specific hyperparameter tuning.

Discussion and Insights

A key advantage of LMD over traditional autoencoders is the "opinionated" nature of diffusion models. While autoencoders may reconstruct OOD data too accurately to allow for detection, diffusion models are specialized in mapping corrupted inputs specifically toward their training distribution.

The choice of masking and distance metrics is critical. The checkerboard mask provides sufficient local context for ID reconstruction while highlighting OOD artifacts. Furthermore, the shift from pixel-wise MSE to perceptual LPIPS was a pivotal "aha" moment, as LPIPS better captures the fragmented nature of OOD reconstructions.

Despite its success, LMD faces challenges regarding computational efficiency. The iterative denoising process of vanilla diffusion models is slow, and the need for multiple passes to stabilize the stochastic signal further increases inference time.

Conclusion

LMD represents a significant step forward in unsupervised OOD detection by utilizing the generative capabilities of diffusion models to probe the geometric properties of image manifolds. Future research will focus on integrating faster sampling techniques, such as consistency models, to make this robust detection framework viable for real-time applications.

Summary updated

BibTeX
@inproceedings{liu2024leveraging,
  author = {Zhenzhen Liu and Jin Peng Zhou and Kilian Q. Weinberger},
  title = {{Leveraging diffusion models for unsupervised out-of-distribution detection on image manifold}},
  booktitle = {Frontiers Artif. Intell},
  year = {2024},
  url = {https://openreview.net/forum?id=Z4uYlBq17R},
}
Figure