On Diffusion Modeling for Anomaly Detection

Victor Livernoche, Vineet Jain, Yashar Hezaveh, Siamak Ravanbakhsh

While Denoising Diffusion Probabilistic Models (DDPMs) are highly effective for generative tasks, their application to anomaly detection has traditionally been bottlenecked by computational inefficiency. Relying on simulating a full reverse diffusion chain makes them impractically slow for real-time monitoring or large datasets.

To address this, researchers have introduced Diffusion Time Estimation (DTE), a novel approach that bypasses the reverse diffusion process entirely by directly predicting the diffusion time of a noisy sample. DTE achieves state-of-the-art results on standard benchmarks, outperforming existing deep learning methods while operating orders of magnitude faster than traditional diffusion models.

The Bottleneck in Diffusion-Based Anomaly Detection

Anomaly detection aims to identify data points that deviate significantly from the norm. In unsupervised and semi-supervised settings, classical methods like $k$-Nearest Neighbors ($k$NN) frequently outperform modern deep learning techniques.

Recently, generative models like DDPMs have shown promise: by adding noise to a sample and using the model to "denoise" it back to the normal data manifold, one can flag the sample as an anomaly if the reconstruction error is high. However, simulating the reverse diffusion process step-by-step for every single data point is incredibly slow. The core question this research addresses is: Can we harness the power of diffusion models for anomaly detection without the massive computational overhead?

The Core Idea: Diffusion Time Estimation (DTE)

The authors realized that explicitly reconstructing the data—learning the exact reverse process—is overkill for anomaly detection. The primary goal is simply to estimate the distance from the input to the normal data manifold.

To achieve this, they propose DTE. The intuition is straightforward: if you add noise to an anomalous point, it will resemble a normal data point that has been diffusing for a long time, simply because it started further away from the normal manifold. By estimating the posterior distribution of the diffusion time for a given input, the model can generate a highly accurate anomaly score.

The researchers developed three variations of this concept:

  1. Non-parametric DTE: The authors mathematically derive the exact analytical form of this posterior distribution, proving it follows an inverse Gamma distribution. They approximate this using $k$-nearest neighbors.
  2. Parametric DTE (Inverse Gamma): To make the method scalable, they train a neural network to predict the scale parameter of this inverse Gamma distribution.
  3. Parametric DTE (Categorical): They train a neural network to classify the timestep into discrete bins. This approach makes fewer assumptions about the distribution's shape and proved to be the most robust and best-performing method.

Key Insights

  • DTE is Essentially a Parametric $k$NN: A fascinating mathematical insight from the paper is that the non-parametric DTE estimator produces an anomaly ranking identical to classical $k$NN. Consequently, the neural network-based Parametric DTE can be viewed as a highly scalable, approximate $k$NN algorithm.
  • Skipping the Reverse Chain: You do not need to generate data to find anomalies. By reframing the problem as predicting the forward diffusion timestep, the model collapses a complex generative task into a simple forward pass of a neural network.
  • Latent Space Beats Pixel Space: Diffusion-based anomaly detection performs significantly better when applied to pre-trained embeddings (latent space) rather than raw image pixels. Self-supervised embeddings tailored to the specific dataset yielded the best results.
  • Standardization is Crucial: Because the forward diffusion process assumes features are centered at zero with unit variance, standardizing the input data is a strictly necessary preprocessing step.

Results and Performance

The models were evaluated on ADBench, a massive anomaly detection benchmark containing 57 datasets (tabular, image embeddings, and NLP embeddings), as well as standard image datasets like VisA, CIFAR-10, MNIST, and SVHN.

Inference Time vs. Average AUC ROC for various anomaly detection methods.

The Categorical Parametric DTE outperformed all other deep learning baselines—including DDPMs, Normalizing Flows, GANs, and VAEs—across the 57 ADBench datasets in both semi-supervised and unsupervised settings.

Crucially, because DTE only requires a single forward pass through a Multi-Layer Perceptron (MLP), its inference time is orders of magnitude faster than DDPMs, which require hundreds of sequential steps to reverse the diffusion process. DTE stands out as one of the few deep learning methods that successfully competes with classical $k$NN in terms of accuracy, while completely bypassing $k$NN's notorious inference-time scalability bottlenecks.

Limitations and Future Work

While DTE is remarkably fast and accurate, it trades off some interpretability. DDPMs, though slow, are highly interpretable because they can output a "denoised" version of the anomaly, showing exactly what a normal version of the data point should look like. DTE can technically approximate this via gradient descent on the density, but it performs worse at this specific task because it wasn't explicitly trained to denoise.

Future work will focus on evaluating DTE on larger, more complex real-world datasets. The authors also note that applying diffusion modeling to detect group and contextual anomalies remains a high-impact, unexplored frontier.

Summary updated

BibTeX
@inproceedings{livernoche2024diffusion,
  author = {Victor Livernoche and Vineet Jain and Yashar Hezaveh and Siamak Ravanbakhsh},
  title = {{On Diffusion Modeling for Anomaly Detection}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=lR3rk7ysXz},
}
Figure