Contrastive Spectral Rectification: Test-Time Defense towards Zero-shot Adversarial Robustness of CLIP
Sen Nie, Jie Zhang, Zhuo Wang, Shiguang Shan, Xilin Chen
TL;DR
Zero-shot CLIP is highly vulnerable to adversarial examples. The authors reveal a spectral fragility: adversarial signals rely on mid-to-high frequencies due to CLIP's spectral bias, while benign content remains stable under frequency attenuation. They propose CSR, a test-time defense comprising spectral-consistency-based detection and a contrastive rectification that guides inputs toward the natural manifold without retraining. Across 16 datasets, CSR achieves state-of-the-art robustness under strong attacks (e.g., +18.1% under AutoAttack) with modest latency and generalizes to segmentation, captioning, and VQA, illustrating its broad practicality. This work offers a practical, universal defense blueprint for CLIP-based systems and LVLM ecosystems.
Abstract
Vision-language models (VLMs) such as CLIP have demonstrated remarkable zero-shot generalization, yet remain highly vulnerable to adversarial examples (AEs). While test-time defenses are promising, existing methods fail to provide sufficient robustness against strong attacks and are often hampered by high inference latency and task-specific applicability. To address these limitations, we start by investigating the intrinsic properties of AEs, which reveals that AEs exhibit severe feature inconsistency under progressive frequency attenuation. We further attribute this to the model's inherent spectral bias. Leveraging this insight, we propose an efficient test-time defense named Contrastive Spectral Rectification (CSR). CSR optimizes a rectification perturbation to realign the input with the natural manifold under a spectral-guided contrastive objective, which is applied input-adaptively. Extensive experiments across 16 classification benchmarks demonstrate that CSR outperforms the SOTA by an average of 18.1% against strong AutoAttack with modest inference overhead. Furthermore, CSR exhibits broad applicability across diverse visual tasks. Code is available at https://github.com/Summu77/CSR.
