Adversarial patches are physically realizable localized noise, which are able to hijack Vision Transformers (ViT) self-attention, pulling focus toward a small, high-contrast region and corrupting the class token to force confident misclassifications. In this paper, we claim that the tokens which correspond to the areas of the image that contain the adversarial noise, have different statistical properties when compared to the tokens which do not overlap with the adversarial perturbations. We use this insight to propose a mechanism, called STRAP-ViT, which uses Jensen-Shannon Divergence as a metric for segregating tokens that behave as anomalies in the Detection Phase, and then apply randomized composite transformations on them during the Mitigation Phase to make the adversarial noise ineffective. The minimum number of tokens to transform is a hyper-parameter for the defense mechanism and is chosen such that at least 50% of the patch is covered by the transformed tokens. STRAP-ViT fits as a non-trainable plug-and-play block within the ViT architectures, for inference purposes only, with a minimal computational cost and does not require any additional training cost/effort. STRAP-ViT has been tested on multiple pre-trained vision transformer architectures (ViT-base-16 and DinoV2) and datasets (ImageNet and CalTech-101), across multiple adversarial attacks (Adversarial Patch, LAVAN, GDPA and RP2), and found to provide excellent robust accuracies lying within a 2-3% range of the clean baselines, and outperform the state-of-the-art.
Figures & tables
Fig. 1 : STRAP-ViT in action: Demonstrating the detection and transformation of tokens which overlap with the adversarial patch using the proposed STRAP-ViT defense technique. In this case, the minimum number of tokens to modify is two ( K=2 ), such that at least 50% of the patch is covered, to render the patch ineffective.
Fig. 2 : Illustration of the statistical separability of the tokens which overlap with the adversarial patch and other tokens from the clean part of the image, using entropy as a metric.
Fig. 3 : STRAP-ViT pipeline: The two-stage adversarial defense framework comprising of the Detection using Token Segregation through Jensen-Shannon Divergence and Mitigation using Token Transformation through composite randomised transformations, preceded by ViT Pre-processing Tokenization and succeeded by Vit Forward Pass.
Attack
Patch Size
Setting
ImageNet Top-1
Top-5
Caltech Top-1
Top-5
Clean Baseline
80.5%
95.4%
90.4%
96.9%
STRAP-ViT on Clean
80.1% (-0.4% ↓ )
95.1% (-0.3% ↓ )
88.6% (-1.8% ↓ )
95.7% (-1.2% ↓ )
Adversarial Patch (GoogleAP) [ 5 ]
40 × 40
No Defence
3.6%
16.4%
5.3%
14.9%
STRAP-ViT
78.8% (+75.2% ↑ )
94.2% (+77.8% ↑ )
87.6% (+82.3% ↑ )
95.4% (+80.5% ↑ )
45 × 45
No Defence
2.9%
13.6%
1.8%
17.9%
TABLE I : Performance of STRAP-ViT against adversarial patch attacks on ViT-B/16 across ImageNet and Caltech-101. Gains are shown as improvements over the no-defence accuracy.
Attack
Patch Size
Setting
ImageNet Top-1
Top-5
Caltech Top-1
Top-5
Clean Baseline
83.8%
99.3%
95.0%
99.8%
STRAP-ViT on Clean
86.0% (+2.2% ↑ )
97.3% (-2.0% ↓ )
93.5% (-1.5% ↓ )
96.9% (-2.9% ↓ )
Adversarial Patch (GoogleAP) [ 5 ]
40 × 40
No Defence
7.2%
20.2%
8.1%
16.7%
STRAP-ViT
83.9% (+76.7% ↑ )
96.7% (+76.5% ↑ )
91.3% (+83.2% ↑ )
98.0% (+81.3% ↑ )
45 × 45
No Defence
7.5%
18.5%
5.6%
20.4%
TABLE II : Performance Analysis of STRAP-ViT on Image Classification Task with the DinoV2 backbone model across datasets (ImageNet and Caltech-101), for three adversarial attacks (Adversarial Patch, LAVAN and GDPA) with varying patch sizes.
Patches
Patch Size
Setting
ImageNet Top-1
Top-5
Caltech Top-1
Top-5
Clean Baseline
80.5%
95.4%
90.4%
96.9%
STRAP-ViT on Clean
80.1% (-0.4% ↓ )
95.1% (-0.3% ↓ )
88.6% (-1.8% ↓ )
95.7% (-1.2% ↓ )
RP2 – TWO Patches
40 × 40
No Defence
31.9%
34.9%
28.1%
37.2%
STRAP-ViT (K=4)
77.2% (+45.3% ↑ )
92.3% (+57.4% ↑ )
88.8% (+60.7% ↑ )
94.6% (+57.4% ↑ )
RP2 – THREE Patches
TABLE III : Performance Analysis of STRAP-ViT on Image Classification Task with the ViT-base-16 model across datasets (ImageNet and Caltech-101), for the RP2 [ 8 ] attack with multiple patches.
Defense
Patch-Size
Robust Acc
Defense
Patch-Size
Robust Acc
Smoothed ViT-B [ 23 ]
32x32
39
JEDI [ 31 ]
40x40
70.6
Certifiable Defense with ViT [ 21 ]
32x32
41.7
Dimension Reduction [ 33 ]
40x40
62.6
PatchCleanser [ 22 ]
32x32
62.1
ODDR [ 32 ]
40x40
74.3
LGS [ 19 ]
40x40
70.6
STRAP (ours)
40x40
78.8
TABLE IV : Performance Comparison of STRAP-ViT with the related works, tested on the ViT model, on the ImageNet dataset with the Adversarial Patch [ 5 ] .
Fig. 4 : A plot of the performance analysis of STRAP-ViT, with multiple adversarial patches ( Adversarial Patch, LAVAN, GDPA) and patch sizes, across two datasets (ImageNet and CalTech-101), also including the clean baseline and the impact of applying STRAP-ViT on clean samples, for reference and comparison.
Vision Transformers (ViTs) remain vulnerable to localized adversarial attacks, e.g., adversarial patches, while recent test-time defenses mitigate them by suppressing image tokens with abnormally high attention scores. These defenses exploit a strong coupling between attention and adversarial effectiveness: adversarial tokens often need to attract substantial attention to influence the prediction. We introduce adversarial decoys, independently optimized image patches that redirect the attention, and therefore related defenses, toward selected target tokens. Rather than jointly optimizing misclassifications and defense evasion, our approach decouples the two objectives: the original adversarial region induces the incorrect prediction, while a separate decoy manipulates the attention ranking used by the defense. A layer-wise objective increases target-token attention and promotes these tokens above competing non-target ones. Since the decoy is optimized independently of the underlying attack, the method is attack-agnostic and can be easily integrated with any existing adversarial patch attack. Experiments on ImageNet across multiple ViT architectures and attacks show that decoys can redirect high attention scores away from the true adversarial region while preserving much of the attack effectiveness. These results reveal a fundamental limitation of using attention magnitude as an indicator of adversarial relevance.
Giulia Marchiori Pietrosanti, Giulio Rossolini, Giorgio Buttazzo
Department of Excellence in Robotics and AI, Sant’Anna School of Advanced Study, Italy
To adopt the Vision Transformers (ViTs) in resource-constrained environment, token pruning is widely used to reduce computational cost without impacting accuracy. However, adversaries have developed targeted attacks against said token pruning techniques to undermine such attempts to make ViTs efficient. In this paper, we propose MOAT, a model-agnostic pre-processing defense pipeline that applies a combination of input transformations to protect efficient ViT implementations against adversarial efficiency attacks. MOAT operates directly on the input without requiring modifications to the model architecture or token pruning mechanism. Experimental results demonstrate that, across all evaluated ViT models, MOAT limits GFLOPs degradation under adversarial attacks to within 3.4% of the original unattacked model.
The widespread use of image classification models in high-risk, real-world situations necessitates making these models robust to slight disturbances or perturbations, such as blurring or sharpening, in the input images. While vision transformers (ViTs) play an integral role in many modern-day multi-modal models like Vision-Language-Models (VLMs) and Vision-Language-Action (VLA) models, they have received a lack of attention in the setting of robustness. In this work, we analyze the effects of adversarial fine-tuning, a popular method for improving model robustness to image perturbations, on a ViT's performance on perturbed and regular images through a mechanistic lens. We adversarially train a ViT on low-frequency and high-frequency image corruptions, and attempt to explain changes in downstream model performance through an examination of the model's attention mechanisms, internal representations, and knowledge evolution. Overall, our results suggest that, while fine-tuning on inputs with common corruptions improves model performance and certainty on new instances of corrupted data, these improvements do not transfer to other classes of corruptions not seen in the training. Additionally, despite observing changes in visual attention and knowledge evolution across layers, we found that adversarial training did not lead to fundamental changes in the sparse representations learned by ViTs.