We propose a test-time defense mechanism against adversarial attacks: imperceptible image perturbations that significantly alter the predictions of a model. Unlike existing methods that rely on feature filtering or smoothing, which can lead to information loss, we propose to "combat noise with noise" by leveraging stochastic resonance to enhance robustness while minimizing information loss. Our approach introduces small translational perturbations to the input image, aligns the transformed feature embeddings, and aggregates them before mapping back to the original reference image. This can be expressed in a closed-form formula, which can be deployed on diverse existing network architectures without introducing additional network modules or fine-tuning for specific attack types. The resulting method is entirely training-free, architecture-agnostic, and attack-agnostic. Empirical results show state-of-the-art robustness on image classification and, for the first time, establish a generic test-time defense for dense prediction tasks, including stereo matching and optical flow, highlighting the method's versatility and practicality. Specifically, relative to clean (unperturbed) performance, our method recovers up to 68.1% of the accuracy loss on image classification, 71.9% on stereo matching, and 29.2% on optical flow under various types of adversarial attacks.
Figures & tables
Figure 1: Diagram. Neural networks are sensitive to perturbations in the input space, which adversarial attacks exploit to manipulate outputs. Existing defense focuses on filtering out unreliable features or denoising either the input or the features. Instead, we propose a novel defense based on stochastic resonance. Controlled transformations are introduced to the input. Features are then aggregated after inverting these transformations. The resulting test-time defense method requires no training and is compatible with diverse architectures. Notably, it not only improves robustness against attacks but also increases the difficulty of crafting adversarial examples, even when the attacker is aware of whether and how stochastic resonance is being used (adaptive adversary).
Method
Architecture
Natural
FGSM
PGD-20
PGD-100
C&W
Ensemble
AutoAttack
AT Madry et al. (2017)
ResNet-18
85.02
56.21
48.22
46.37
47.38
45.90
44.11
+ FD Xie et al. (2019)
85.14
56.81
48.54
46.70
47.72
45.82
44.57
+ CAS Bai et al. (2021)
85.78
55.57
50.42
49.91
53.47
46.46
44.23
+ CIFS Yan et al. (2021)
79.87
56.53
49.80
48.17
49.89
47.26
43.94
+ FSR Kim et al. (2023)
81.46
58.07
52.47
51.02
49.44
48.34
46.41
+ TTE Pérez et al. (2021)
85.25
59.20
53.00
51.65
52.45
50.60
-
Table 1: Defense against adversarial attacks on CIFAR-10. Unlike baselines, we perform defense purely at test-time, and achieve state-of-the-art robustness under different attacks. Even in an adaptive setting (worst-case) where the attacker is fully aware of how defense is applied, the effectiveness of adversarial attacks is still notably reduced, while the computational cost for executing such attacks is significantly increased.
Att. Strength ( ϵ )
8/255
4/255
2/255
1/255
Metric
Top-1
Top-5
Top-1
Top-5
Top-1
Top-5
Top-1
Top-5
No Defense
4.51
19.55
12.25
42.15
29.79
65.09
48.09
78.13
Ours ( d=1 )
11.66
46.27
27.85
65.80
45.94
77.63
57.48
83.43
Ours ( d=2 )
18.78
58.58
36.42
72.86
51.58
80.85
60.41
84.77
Ours ( d=3 )
25.77
65.88
42.52
76.75
54.94
82.64
62.08
85.50
Table 2: ImageNet with ViT-Small. Increasing the level of stochastic resonance consistently improves both Top-1 and Top-5 accuracy under adversarial attacks. Relative to the clean baseline (72.9 Top-1, 92.91 Top-5), our method recovers up to 55.8% of the Top-1 accuracy loss and 68.1% of the Top-5 accuracy loss.
Figure 2: Varying levels of stochastic resonance. Increasing the stochastic resonance level enhances robustness across all settings. Notably, our approach achieves superior performance even under adaptive attacks (Ours-WorstCase), despite the baseline (FSR) being evaluated only in the non-adaptive case.
Figure 3: Qualitative results on stereo matching. We demonstrate a significant reduction in prediction errors. This technique holds significant potential for safety-critical applications where stereo vision must remain reliable under diverse environmental conditions and adversarial threats. Additional visualizations at Appendix N .
Attack Strength ( ϵ )
0.02
0.01
0.005
0.002
Metric
MAE
RMSE
D1-err
MAE
RMSE
D1-err
MAE
RMSE
D1-err
MAE
RMSE
D1-err
FGSM
No Defense
14.83
24.10
97.33
8.49
14.53
90.49
5.05
7.70
74.71
3.01
3.49
38.12
Latent Smoothing Addepalli et al. (2021)
13.42
22.09
96.61
8.12
13.69
89.25
4.89
7.05
73.01
2.89
3.32
36.25
Randomized Smoothing Cohen et al. (2019)
14.20
22.41
97.26
7.38
11.21
89.44
4.26
5.19
70.49
2.78
3.18
30.76
Ours ( d=1 )
10.12
15.81
95.80
6.46
9.92
86.30
4.39
5.93
68.55
2.78
3.18
31.99
Ours ( d=2 )
9.22
13.88
94.61
6.13
8.87
84.49
4.19
5.43
66.74
2.73
3.12
31.18
Table 3: Stochastic resonance enhances stereo matching robustness. Stochastic resonance significantly mitigates errors across all settings, reducing error by up to 71.89% (MAE, attacked by PGD with ϵ=0.005 ).
Figure 4: Improved optical flow robustness. By ensembling in the latent feature space rather than the output space, stochastic resonance consistently achieves stronger robustness across all resonance levels.
Figure 5: Qualitative results for optical flow. Our method substantially mitigates the degradation caused by both PGD and FGSM attacks. Such robustness is critical for perception systems that rely on motion estimation.
mIoU ↑
Boundary mIoU ↑
Attack
ϵ
No SR
d=1
d=2
d=3
No SR
d=1
d=2
d=3
CosPGD
2/255
18.40
25.53
31.14
32.75
15.14
21.57
26.71
28.21
4/255
17.16
22.42
26.29
27.38
13.74
18.61
22.26
23.28
8/255
15.39
19.15
21.71
22.41
12.18
15.57
17.96
18.62
SegPGD
2/255
1.02
5.64
18.24
23.46
1.08
6.06
17.84
22.11
4/255
0.47
1.50
6.43
9.06
0.49
1.66
6.79
9.32
Table 4: Semantic segmentation on Cityscapes under attack. We report mIoU and boundary mIoU (%) for the baseline model and three levels of stochastic resonance. Higher is better for both metrics.
Backbone
Method
RMSE ↓
RMSE-log ↓
AbsRel ↓
SqRel ↓
ViT-B/14
Clean
0.396
0.135
0.100
0.061
No Defense
0.645
0.191
0.168
0.383
Ours
0.564
0.181
0.155
0.163
Error Reduced (%)
32.5
17.9
19.1
68.3
ViT-L/14
Clean
0.373
0.127
0.093
0.054
No Defense
0.588
0.189
0.163
0.236
Table 5: Monocular depth on NYU-V2 with larger ViT backbones. We evaluate under PGD-10 attacks with ϵ=8/255 . Error reduction is measured as relative recovery toward the clean baseline.
Defense
Clean
Baseline
d=1
d=2
d=3
No Defense
0.302
-0.025
0.064
0.145
0.179
AT
0.302
0.136
0.195
0.231
0.249
Table 6: Vision-language alignment under attack. On CLIP ViT-L/14 under PGD attacks, stochastic resonance improves image-text alignment as the resonance level increases, and complements adversarial training (AT).
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
Layer
Mean Correlation
conv_proj
0.0897
block_00
0.2107
block_01
0.2518
block_02
0.3311
block_03
0.3712
block_04
0.3781
Appendix
Table 7: Mean pairwise correlation of the aligned perturbation terms vi across layers of a ViT-S model under an adaptive PGD-100 attack on ImageNet. The values remain far from perfect alignment, supporting the decorrelation assumption used in the analysis.
Translation Radius d
0
1
2
3
4
L1 Distance (Adv. vs. Clean)
12.30
5.29
3.50
2.64
2.12
Appendix
Table 8: L1 distance between adversarial and clean DINO embeddings for different translation radius d increases.
Metric
d=0
d=1
d=2
d=3
# Forward Passes
1
9
25
49
Wall-clock Time (s)
0.095
0.114
0.133
0.158
SR Forward Time (excluding interpolation)
0.007
0.010
0.019
0.028
Top-1 Acc @ ϵ=8/255
8.51
18.40
20.01
21.17
Top-1 Acc @ ϵ=4/255
9.45
19.54
21.02
22.04
Top-1 Acc @ ϵ=2/255
11.10
21.02
22.44
23.44
Appendix
Table 9: Image Classification performance and computational cost on ImageNet with different translation radius d .
Metric
d=0
d=1
d=2
d=3
# Forward Passes (can be parallelized)
1
9
25
49
Memory (CIFAR)
114.50 MB
141.50 MB
182.93 MB
260.50 MB
Memory (ImageNet)
157.80 MB
225.19 MB
384.03 MB
650.47 MB
Appendix
Table 10: Memory footprint of ResNet-50 on different size input with different degree of translation radii d
Dataset / Metric
No Defense
SR ( d=2 )
SR ( d=3 )
ImageNet Top-1
74.90
75.09
75.16
ImageNet Top-5
92.21
92.30
92.42
CIFAR-10 Accuracy
93.26
93.50
93.64
Appendix
Table 11: Clean performance. Stochastic resonance preserves and slightly improves clean accuracy on both ImageNet and CIFAR-10, indicating that the method does not trade clean performance for robustness.
Att. Strength ( ϵ )
8/255
4/255
2/255
1/255
Metric
Top-1
Top-5
Top-1
Top-5
Top-1
Top-5
Top-1
Top-5
No Defense
8.51
26.19
9.45
27.92
11.10
30.63
15.21
36.76
Initial Conv.
16.91
34.66
17.36
35.28
18.12
36.30
19.59
38.25
Res. Block 1
22.44
44.95
23.39
46.03
24.84
47.64
27.57
50.80
Res. Block 2
24.88
48.54
25.90
49.66
27.23
51.19
30.11
54.15
Res. Block 3
21.76
44.28
22.73
45.47
24.14
47.14
27.18
50.20
Appendix
Table 12: Layer-wise ablation on ResNet-50. Adversarial perturbations resemble high-frequency noise. Applying stochastic resonance through shallow layers is sufficient to defend against adversarial attacks, reducing the overall computational cost.
Att. Strength ( ϵ )
8/255
4/255
2/255
1/255
Metric
Top-1
Top-5
Top-1
Top-5
Top-1
Top-5
Top-1
Top-5
No Defense
8.51
26.19
9.45
27.92
11.10
30.63
15.21
36.76
Ours ( d=1 )
18.40
40.36
19.54
42.65
21.02
43.86
24.66
47.81
w/ Rotation
20.01
41.32
20.84
42.39
22.10
43.89
24.72
46.89
Ours ( d=2 )
20.01
42.22
21.02
43.45
22.44
45.32
25.80
48.97
w/ Rotation
18.86
38.67
19.55
39.50
20.36
40.48
22.01
42.50
Appendix
Table 13: Translation vs. rotation as purposeful perturbations. On ResNet-50, rotations improve robustness relative to the undefended model across all attack strengths and resonance levels. However, translations are more effective at higher resonance levels and avoid the interpolation overhead required by rotations. This supports our use of translations as the default instantiation of stochastic resonance.
Layer
Corr. (Trans.)
Corr. (Rot.)
CosSim (Trans.)
CosSim (Rot.)
Block 1
0.7540
0.6487
0.8357
0.7739
Block 2
0.5933
0.4569
0.6756
0.5766
Block 3
0.6752
0.5095
0.7771
0.6756
Block 4
0.8808
0.7719
0.8954
0.8032
Appendix
Table 14: Feature alignment under translations and rotations. We compare features after each residual block of ResNet-50, after applying the inverse transformation in latent space. Translations yield consistently higher correlation and cosine similarity than rotations, indicating better feature alignment after inversion. This explains why rotations still improve robustness relative to no defense, but are less effective than translations.
Setting
Clean
FGSM
PGD
2/255
4/255
8/255
2/255
4/255
8/255
No Defense
89.13
31.41
24.01
21.76
0.00
0.01
0.03
Ours ( d=1 )
89.99
71.68
71.51
71.55
58.19
57.03
49.87
Ours ( d=2 )
89.94
73.40
73.30
73.44
69.08
68.14
61.41
Ours ( d=3 )
89.92
74.05
73.99
74.08
73.32
72.30
65.38
Appendix
Table 15: Stochastic resonance on MLP-Mixer. Even without explicit convolutional translation equivariance, stochastic resonance substantially improves robustness under both FGSM and PGD attacks while preserving clean accuracy.
Setting
Accuracy (%) ↑
Attacked
1.72
Feature-space defense [ 70 ]
8.13
Feature-space defense [ 70 ] + Ours
8.56
Appendix
Table 16: Combination with feature-space defense. Stochastic resonance further improves robustness when combined with the feature-space stochastic defense of [ 70 ] , suggesting that the two mechanisms are complementary.
Setting
Accuracy (%) ↑
Attacked
2.14
Feature-space defense [ 70 ]
11.09
Ours only
12.36
Appendix
Table 17: Constrained feature-space attack. When the feature-space attack is constrained by a maximum perturbation magnitude, stochastic resonance alone provides a reasonable level of robustness and outperforms the feature-space defense baseline in this setting.
Figure 6: Visual results on stereo matching against FGSM attack, without and with SR, ϵ=0.02
Figure 7: Visual results on stereo matching against FGSM attack, without and with SR, ϵ=0.01
Figure 8: Visual results on stereo matching against FGSM attack, without and with SR, ϵ=0.005
Figure 9: Visual results on stereo matching against PGD attack, without and with SR, ϵ=0.01
Figure 10: Visual results on stereo matching against PGD attack, without and with SR, ϵ=0.005
Figure 11: Visual results on stereo matching against PGD attack, without and with SR, ϵ=0.002
Figure 12: Original images and their corresponding attacked images and perturbations using FGSM and PGD methods on optical flow. The attacks mostly target the main object observed in the image.