Protego: Detecting Adversarial Examples for Vision Transformers via Intrinsic Capabilities

Jialin Wu, Kaikai Pan, Yanjiao Chen, Jiangyi Deng, Shengyuan Pang, Wenyuan Xu

Abstract

Transformer models have excelled in natural language tasks, prompting the vision community to explore their implementation in computer vision problems. However, these models are still influenced by adversarial examples. In this paper, we investigate the attack capabilities of six common adversarial attacks on three pretrained ViT models to reveal the vulnerability of ViT models. To understand and analyse the bias in neural network decisions when the input is adversarial, we use two visualisation techniques: attention rollout and grad attention rollout. To prevent ViT models from adversarial attack, we propose Protego, a detection framework that leverages the transformer's intrinsic capabilities to detect adversarial examples. This is challenging due to the diversity of attack strategies adopted by adversaries. Inspired by the attention mechanism, we know that the token of prediction contains information from the entire input sample. Additionally, the attention region for adversarial examples differs from that of normal examples. We train a detector that achieves superior performance compared to existing methods. Our experiments demonstrate high effectiveness, with AUC scores exceeding 0.95 across six adversarial attack methods.

Introduction

As Vision Transformers (ViTs) become the backbone of modern computer vision—powering everything from autonomous systems to the burgeoning "metaverse"—their security is increasingly critical. Like the Convolutional Neural Networks (CNNs) that preceded them, ViTs are highly susceptible to adversarial examples: images with imperceptible pixel-level perturbations that trick a model into making confident, incorrect predictions. While many defense strategies exist for CNNs, they do not always translate well to the attention-based architecture of Transformers. There is a pressing need for "reactive" defenses that can detect these "digital illusions" before they reach the decision-making stage, without requiring expensive retraining of the primary model.

The Protego Framework

We introduce Protego (named after the shield charm from Harry Potter), a lightweight, "plug-in" detector designed to shield ViTs from adversarial attacks by leveraging the intrinsic capabilities of the Transformer architecture.

The Protego framework: from patch extraction and transformer blocks to the training of the plug-in detector.

The Protego pipeline consists of several key stages:

  1. Feature Extraction: Instead of relying on the final classification output, Protego examines the internal state of the Transformer's encoder. It specifically extracts features from the first token ($b^1$) of the encoder's output. Due to the self-attention mechanism, this token aggregates global information from the entire image, making it a rich source of diagnostic data.
  2. Processing and Training: The extracted features are processed to identify patterns unique to adversarial noise. Protego utilizes a single-layer linear neural network as its detector. This simplicity is a key advantage, making the framework computationally efficient and easy to integrate as a "plug-in" for existing models.
  3. Detection: The detector is trained to distinguish between the feature distributions of clean images and those of common adversarial attacks, such as PGD, FGSM, and CW.

The "Attention Shift" Phenomenon

The core hypothesis behind Protego is that adversarial noise "distracts" the model. In a normal image, attention is concentrated on the primary object of interest (e.g., an eagle's head). However, in an adversarial image, the attention regions shift significantly toward edges or background noise.

Visualization of attention regions for normal vs. adversarial examples using Attention Rollout and Grad-based methods, showing how adversarial noise scatters the model's focus.

To validate this, we used "Attention Rollout" and "Grad Attention Rollout" to visualize the model's focus. As shown in the visualizations, while a clean image of a bird results in a tight attention heat map on the bird, an adversarial version of that same image scatters the heat map across the frame. This "smoking gun" evidence proves that adversarial attacks work by hijacking the attention mechanism, a shift that Protego is specifically designed to detect.

Experimental Results and Analysis

We evaluated Protego using the ImageNet (ILSVRC2012) dataset across three pre-trained architectures: ViT-B-16, ViT-B-32, and DeiT-Tiny.

  • Detection Accuracy: Protego demonstrated exceptional performance, with AUC scores exceeding 0.95 for most attack methods. In specific cases, such as detecting FGSM attacks on ViT-B-16, the detector achieved a perfect AUC of 1.0.
  • Baseline Comparison: Protego significantly outperformed existing baselines like LID (Local Intrinsic Dimensionality). For instance, on the CW attack for ViT-B-16, LID scored an AUC of 0.65, while Protego reached 0.97.
  • Robustness: The detector remained effective even against specialized "Patch-fool" attacks designed to target the patch-based nature of Transformers.

One of the most significant findings is that a simple one-layer linear network is sufficient for high-accuracy detection. This suggests that the features extracted from the Transformer are already linearly separable in high-dimensional space, making the detector extremely computationally efficient.

Conclusion and Future Work

Protego offers a highly effective and efficient solution for securing Vision Transformers. By tapping into the model's internal self-attention features, it identifies adversarial examples with near-perfect accuracy. However, the current method relies on a specific feature subtraction technique during training that may not be universally applicable, and the detector currently lacks high transferability across different architectures without retraining.

Future work will focus on expanding this research into Multimodal Large Language Models (MLLMs). As we move toward models that process both text and images, detecting cross-modal adversarial "spells" will be a critical security frontier.

Summary updated

Abstract

Transformer models have excelled in natural language tasks, prompting the vision community to explore their implementation in computer vision problems. However, these models are still influenced by adversarial examples. In this paper, we investigate the attack capabilities of six common adversarial attacks on three pretrained ViT models to reveal the vulnerability of ViT models. To understand and analyse the bias in neural network decisions when the input is adversarial, we use two visualisation techniques that are attention rollout and grad attention rollout. To prevent ViT models from adversarial attack, we propose Protego, a detection framework that leverages the transformer intrinsic capabilities to detection adversarial examples of ViT models. Nonetheless, this is challenging due to a diversity of attack strategies that may be adopted by adversaries. Inspired by the attention mechanism, we know that the token of prediction contains all the information from the input sample. Additionally, the attention region for adversarial examples differs from that of normal examples. Given these points, we can train a detector that achieves superior performance than existing detection methods to identify adversarial examples. Our experiments have demonstrated the high effectiveness of our detection method. For these six adversarial attack methods, our detector's AUC scores all exceed 0.95. Protego may advance investigations in metaverse security.
BibTeX
@inproceedings{wu2024protego,
  author = {Jialin Wu and Kaikai Pan and Yanjiao Chen and Jiangyi Deng and Shengyuan Pang and Wenyuan Xu},
  title = {{Protego: Detecting Adversarial Examples for Vision Transformers via Intrinsic Capabilities}},
  booktitle = {MetaCom},
  year = {2024},
  doi = {10.1109/metacom62920.2024.00029},
}
Figure