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

DIFFender: Diffusion-Based Adversarial Defense Against Patch Attacks

Caixin Kang, Yinpeng Dong, Zhengyi Wang, Shouwei Ruan, Yubo Chen, Hang Su, Xingxing Wei

Abstract

Adversarial patch attacks pose a significant threat to real-world computer vision systems by introducing localized, visible disruptions that can deceive classifiers. This paper presents DIFFender, a unified defense framework leveraging the generative capabilities of diffusion models. By identifying a phenomenon termed Adversarial Anomaly Perception (AAP)—the distributional discrepancy in patch regions during the denoising process—DIFFender achieves precise patch localization and high-fidelity restoration. Combined with a few-shot prompt-tuning strategy, the framework demonstrates superior robustness and generalizability across diverse datasets and physical-world scenarios without requiring extensive model retraining.

Introduction

While much of adversarial research focuses on $\ell_p$-norm attacks—tiny, global changes designed to be invisible—patch attacks are far more dangerous in practical applications. These attacks involve placing localized, visible patterns, such as stickers, on objects to manipulate model outputs. For instance, a small patch can cause an autonomous vehicle to misinterpret a traffic sign or a facial recognition system to misidentify a subject.

Existing defenses often struggle with a trade-off: they either fail to generalize to unseen patch types or "over-purify" images, introducing blurry artifacts that degrade the performance of downstream tasks. DIFFender addresses these challenges by utilizing the inherent generative priors of diffusion models to detect and neutralize these localized anomalies.

The visual pipeline of DIFFender, illustrating the transition from an adversarial image to a restored output via patch localization and mask estimation.

Methodology

Adversarial Anomaly Perception (AAP)

The core innovation of DIFFender is the discovery of Adversarial Anomaly Perception (AAP). Diffusion models, trained on natural image distributions, essentially "reject" adversarial patches because they do not conform to learned patterns. During the denoising process, the patch region exhibits significant distributional discrepancies compared to natural image segments. By comparing denoised outputs generated with different textual prompts (e.g., an "adversarial" prompt versus an empty prompt), DIFFender can pinpoint the exact location of the patch.

Patch Restoration and Prompt Tuning

Once localized, the patch is masked, and the diffusion model acts as an intelligent inpainter. It fills the masked area to restore the underlying content while maintaining global coherence, guided by a "clean" textual prompt.

To ensure efficiency, DIFFender employs a few-shot prompt-tuning algorithm. Rather than retraining the massive diffusion model, the authors optimize small "learnable vectors" (prompts) using only 8 examples. This optimization uses a multi-faceted loss function: cross-entropy for mask accuracy, $L_1$ loss for visual fidelity, and perceptual feature loss to ensure the restored image remains compatible with downstream classifiers.

The DIFFender architecture, showing the Unified Diffusion Model, the Prompt Tuning module, and the dual tasks of Patch Localization and Restoration.

Evaluation and Key Results

The framework was evaluated on ImageNet, LFW (Labeled Faces in the Wild), and a custom physical-world dataset involving real stickers on objects under varying environmental conditions.

  • Superior Robustness: On ImageNet using Inception-v3, DIFFender achieved a robust accuracy of 88.3% against adaptive patch attacks, significantly outperforming existing state-of-the-art defenses like SAC (84.2%) and Jedi (67.6%).
  • Generalizability: The defense demonstrated strong cross-model transferability. Prompts tuned on a CNN (Inception-v3) remained effective when defending a Vision Transformer (ViT), indicating that the learned prompts capture fundamental adversarial characteristics.
  • Physical World Success: In real-world tests, DIFFender maintained an accuracy of 80.9% despite changes in camera yaw, pitch, and lighting, whereas undefended models dropped to as low as 28.9%.

Conclusion

DIFFender demonstrates that "tuning the language" (prompts) is a highly efficient and viable alternative to tuning model weights for security purposes. By leveraging the "struggle" of diffusion models to process adversarial noise, the framework provides a robust tool for both detection and restoration. Future work will focus on reducing computational overhead to enable real-time application in high-speed environments like autonomous driving and expanding the framework to video data.

Summary updated

BibTeX
@inproceedings{kang2024diffender,
  author = {Caixin Kang and Yinpeng Dong and Zhengyi Wang and Shouwei Ruan and Yubo Chen and Hang Su and Xingxing Wei},
  title = {{DIFFender: Diffusion-Based Adversarial Defense Against Patch Attacks}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-72943-0\_8},
}
Figure