Defending Backdoor Attacks on Vision Transformer via Patch Processing

Khoa D. Doan, Yingjie Lao, Peng Yang, Ping Li

TL;DR

Vision Transformers (ViTs) are highly vulnerable to backdoor attacks, but their unique patch-based architecture offers a hidden defense mechanism. By randomly dropping or shuffling image patches at test time, this paper introduces the first ViT-specific defense that reliably detects both patch-based and blending-based backdoor triggers without destroying clean data accuracy.

What Problem Does This Paper Address?

Backdoor attacks pose a severe threat to deep learning security. During the training phase, an attacker injects a hidden "trigger" into a small fraction of the dataset and changes their labels to a target class. The compromised model learns to behave perfectly on clean data but maliciously flips its prediction whenever the trigger is present.

Triggers can be localized (like a small pixel square) or globally distributed (like a blended reflection overlay), as shown in Figure 1.

Figure 1: Clean and backdoor samples with local patch-based trigger (a square in bottom right corner) and global blending-based trigger (an embedded reflection).

While much work has focused on defending Convolutional Neural Networks (CNNs) against these threats, the vulnerability of Vision Transformers (ViTs) remains understudied. Because ViTs lack the spatial inductive biases inherent to CNNs and instead process images as sequences of patches, standard CNN-focused defenses fail to protect them efficiently. This paper fills the gap by analyzing ViT backdoor vulnerabilities and proposing a tailored defense strategy.

Methods

The authors exploit the fundamental design of ViTs, which divide an image into a grid of discrete patches before applying positional encodings and self-attention. They introduce two test-time patch processing techniques:

  1. PatchDrop: Randomly discarding a percentage of image patches to disrupt localized triggers.
  2. PatchShuffle: Randomly shuffling the spatial order of the patches to disrupt global, blending-based triggers.

By running an input image through multiple inference trials with these random perturbations, the defense tracks how often the model's predicted label changes. Because clean images and backdoored images react differently to these spatial disruptions, the authors design an anomaly detection algorithm (Algorithm 1) that flags inputs exceeding specific prediction-instability thresholds ($k_d$ and $k_s$).

Datasets

The method is evaluated on three standard image classification benchmarks:

  • CIFAR10
  • GTSRB (German Traffic Sign Recognition Benchmark)
  • TinyImageNet

Key Insights and Ideas

  • ViTs are inherently vulnerable: Left undefended, ViTs achieve backdoor Attack Success Rates (ASR) above 96% across all datasets, making them just as susceptible as CNNs.
  • The PatchDrop Asymmetry: For local patch-based attacks (like BadNets), dropping patches causes the ViT's backdoor ASR to plummet rapidly, while its clean-data accuracy remains remarkably resilient. CNNs do not exhibit this wide gap, as their clean accuracy drops at a similar rate to the ASR under occlusions.
  • The PatchShuffle Asymmetry: For global blending-based attacks (like ReFool), shuffling patches destroys the global semantic structure needed for clean classification, causing clean accuracy to drop. However, because the backdoor trigger is blended globally across the entire pixel space, the model still detects it, keeping the ASR high.
  • Exploiting the Gaps: These distinct behaviors create measurable sensitivity gaps between clean and poisoned samples that are unique to ViTs, allowing for highly effective test-time detection.

Key Results

  • High Detection Accuracy: The proposed defense achieves a True Positive Rate (TPR) of over 90% in detecting backdoor samples for ViT and DeiT models across almost all datasets.
  • Low False Positives: Unlike CNNs, which frequently misclassify clean samples as backdoored under patch processing (resulting in low True Negative Rates), ViTs maintain exceptionally high TNRs, falsely flagging clean samples less than 3% of the time.
TPR and TNR for PatchDrop
  • Effective Data Purification: When used to filter poisoned training sets, retraining on the purified data successfully reduces the ASR to random-guess levels (e.g., dropping from ~99% to ~10% on CIFAR10 and <1% on GTSRB) while fully preserving the model's clean-data accuracy.

Limitations and Future Work

  • Threshold Calibration: The defense ideally requires access to a small set of clean validation samples (less than 1000) to calibrate the optimal percentile thresholds ($k_d$ and $k_s$). Although a heuristic is provided for cases where no clean data is available ($k_d=0, k_s=T$), it is less optimized.
  • Advanced Anomaly Detection: The current framework uses a straightforward thresholding mechanism based on label change frequencies. The authors note that integrating more sophisticated anomaly detection algorithms could further improve the detection rate, leaving this as an open direction for future research.

Summary updated

BibTeX
@inproceedings{doan2023defending,
  author = {Khoa D. Doan and Yingjie Lao and Peng Yang and Ping Li},
  title = {{Defending Backdoor Attacks on Vision Transformer via Patch Processing}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i1.25125},
}
Figure