NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

DiffDefense: Defending Against Adversarial Attacks via Diffusion Models

Hondamunige Prasanna Silva, Lorenzo Seidenari, Alberto Del Bimbo

Introduction

Deep learning models are notoriously fragile. Tiny, imperceptible perturbations to an input image—known as adversarial attacks—can cause a classifier to fail spectacularly. While adversarial training is a common defense, it often requires retraining models on specific attacks, making them brittle to novel threats. Generative defenses, such as Defense-GAN, attempt to "purify" the image before classification by projecting it onto a clean data manifold. However, GANs are unstable and often slow. DiffDefense introduces a "plug-and-play" mechanism using Denoising Diffusion Probabilistic Models (DDPMs) to provide a faster, more stable, and highly robust reconstruction-based defense.

Methodology: Latent Optimization for Purification

The core of DiffDefense is a reconstruction algorithm based on the reverse process of a diffusion model. Unlike standard diffusion sampling, which starts from random noise to generate a new image, DiffDefense optimizes the initial noise ($z_T$) to reconstruct a "clean" version of an attacked image $x^*$.

Overview of the DiffDefense reconstruction process, showing the optimization of the latent code to move from an attacked image back to the clean data manifold.

The process involves several key steps:

  1. Latent Initialization: The algorithm begins with a latent code $z_T$ (initial noise).
  2. Reverse Diffusion: It runs the reverse diffusion process to generate a reconstruction $x_r$.
  3. Loss Calculation: The Mean Square Error (MSE) between the reconstruction $x_r$ and the attacked input $x^*$ is calculated.
  4. Gradient Descent: The gradient of this loss is used to update the latent code $z_T$.

By iterating this process (typically $L=5$ iterations), the system finds a latent code that produces an image semantically similar to the input but residing on the "clean" data manifold learned by the diffusion model. This effectively strips away malicious perturbations before the image reaches the classifier.

Experimental Results

The authors evaluated DiffDefense on the MNIST and KMNIST (Kuzushiji-MNIST) datasets. KMNIST serves as a more complex drop-in replacement for MNIST, featuring Japanese cursive characters.

Quantitative results comparing classifier accuracy with and without DiffDefense across various attack types on MNIST and KMNIST.

As shown in the results, DiffDefense provides a massive boost in robustness. On MNIST, a "DeepFool" white-box attack reduces classifier accuracy to a mere 0.95%. DiffDefense restores this to 98.16%. Similar improvements are seen across PGD and FGSM attacks. Notably, the defense is effective against both white-box and black-box attacks without requiring any modification to the underlying classifier.

In terms of speed, DiffDefense is significantly more efficient than previous generative defenses. It performs a reconstruction in approximately 0.28 seconds on a TitanXP GPU, compared to 0.675s for Defense-GAN and up to 5 seconds for other diffusion-based purification methods.

Key Insights

Beyond raw accuracy, the paper highlights several advantages of the diffusion-based approach:

  • Stability: Unlike GANs, which involve a difficult minimax training objective, DDPMs are trained with a simple MSE loss, making the defense easier to deploy and more reliable.
  • Attack Detection: A significant finding is that clean images are easier for the model to reconstruct than adversarial ones. By monitoring the reconstruction error, the system can flag potential attacks with high precision (AUC near 1.0 for many attack types).
  • Generalization: Because the model only learns the distribution of "clean" data, it does not need to be tuned for specific attacks, allowing it to generalize to sophisticated "unseen" threats like AutoAttack and Square Attack.

Conclusion and Future Work

DiffDefense demonstrates that diffusion models can be a practical and powerful tool for adversarial defense. While currently tested on lower-resolution datasets like MNIST and KMNIST, the method's "plug-and-play" nature makes it a promising candidate for broader applications. Future work will focus on scaling this optimization-based reconstruction to high-resolution datasets like ImageNet, which will likely require more advanced ODE/SDE solvers to maintain speed and accuracy.

Summary updated

BibTeX
@inproceedings{silva2023diffdefense,
  author = {Hondamunige Prasanna Silva and Lorenzo Seidenari and Alberto Del Bimbo},
  title = {{DiffDefense: Defending Against Adversarial Attacks via Diffusion Models}},
  booktitle = {ICIAP},
  year = {2023},
}
Figure