GOOD: Training-Free Guided Diffusion Sampling for Out-of-Distribution Detection

Xin Gao, Jiyao Liu, Guanghao Li, Yueming Lyu, Jianxiong Gao, Weichen Yu, Ningsheng Xu, Liang Wang, Caifeng Shan, Ziwei Liu, Chenyang Si

Abstract

Out-of-distribution (OOD) detection is essential for ensuring the reliability of machine learning models in real-world applications. Existing methods for generating synthetic outliers often rely on manual text-prompt engineering, which is unpredictable and computationally expensive. This paper introduces GOOD (Guided OOD sampling), a training-free framework that directly guides the diffusion denoising process using gradients from off-the-shelf classifiers. By combining image-level and feature-level guidance, GOOD generates diverse, high-quality OOD samples that effectively expose model vulnerabilities. Our approach significantly improves OOD detection performance on ImageNet-100 and CIFAR-100 while reducing computational overhead compared to existing generative pipelines.

Introduction

For AI systems to be deployed safely, they must possess the ability to identify inputs that differ significantly from their training data. Out-of-distribution (OOD) detection aims to flag such anomalies. A prominent technique for improving this capability is "Outlier Exposure" (OE), where models are trained on synthetic OOD data to learn conservative decision boundaries.

However, generating effective synthetic outliers is challenging. Current text-to-image diffusion-based methods often rely on perturbing text embeddings, which can lead to unpredictable results—either generating images too similar to the training set or producing unrecognizable noise. Furthermore, these methods often fail to capture non-semantic anomalies like domain shifts or unusual textures.

Methodology

The proposed GOOD framework abandons text-embedding perturbation in favor of direct gradient-based guidance during the diffusion model's denoising process. This approach requires no additional training and leverages the knowledge already captured by off-the-shelf classifiers.

Overview of the GOOD framework including guided sampling, outlier exposure training, and test-time detection.

GOOD employs a dual-level guidance strategy:

  1. Image-Level Guidance ($GOOD_{img}$): This uses the classifier's "free energy" (negative log-likelihood) to push the diffusion process toward low-density pixel regions, generating images the classifier finds highly unlikely.
  2. Feature-Level Guidance ($GOOD_{feat}$): Operating in the classifier's latent space, this uses k-Nearest Neighbors (k-NN) distance to steer samples into feature-sparse areas, encouraging the creation of semantically novel features.

To ensure a wide spectrum of anomalies, GOOD utilizes Balanced Sampling, varying guidance step sizes to produce everything from subtle edge cases to extreme outliers. At test time, a Unified OOD Score adaptively combines image-level and feature-level metrics based on the KL divergence between test and validation sets.

Experimental Setup

The framework was evaluated using the following datasets:

  • In-Distribution (ID): ImageNet-100 and CIFAR-100.
  • OOD Evaluation (ImageNet-100): iNaturalist, Places, SUN, and Textures.
  • OOD Evaluation (CIFAR-100): SVHN, Places365, LSUN-R, ISUN, and Textures.

Results

GOOD demonstrates superior performance across standard benchmarks:

  • ImageNet-100: Achieved state-of-the-art results with an FPR95 of 17.68% and an AUROC of 96.30%, outperforming recent methods such as Dream-OOD and NCIS.
  • CIFAR-100: Reduced the average FPR95 to 19.50% (from 34.45% in previous work) and improved AUROC to 94.68%.
  • Efficiency: By bypassing complex latent space construction and embedding alignment, GOOD offers substantial computational savings, reducing the time required for outlier generation.

Discussion and Insights

A key finding is that directly using classifier gradients is far more controllable than text-prompt manipulation. Grad-CAM visualizations reveal that GOOD specifically targets and distorts features critical to the classifier's decision-making process while maintaining overall image coherence.

Visual comparison of image-level and feature-level guidance strategies using Grad-CAM to highlight targeted regions.

The two guidance types are complementary: image-level guidance often results in holistic, abstract distortions (e.g., surreal colors), whereas feature-level guidance produces subtle "hard negatives" (e.g., novel patterns on familiar objects). Additionally, the research highlights the importance of resolution matching; using a native 128x128 diffusion model for lower-resolution datasets like CIFAR-100 yields better alignment and detection performance than downsampling from larger models.

Conclusion

GOOD provides a robust, training-free solution for generating synthetic outliers for OOD detection. While its diversity is limited by the underlying pre-trained diffusion model, it sets a new standard for controllable and efficient outlier exposure. Future work may explore deeper integration of diffusion features with OOD objectives to synthesize even more targeted anomalies.

Summary updated

BibTeX
@inproceedings{gao2025good,
  author = {Xin Gao and Jiyao Liu and Guanghao Li and Yueming Lyu and Jianxiong Gao and Weichen Yu and Ningsheng Xu and Liang Wang and Caifeng Shan and Ziwei Liu and Chenyang Si},
  title = {{GOOD: Training-Free Guided Diffusion Sampling for Out-of-Distribution Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=lRkeVFL85X},
}
Figure