CLIP is Strong Enough to Fight Back: Test-time Counterattacks towards Zero-shot Adversarial Robustness of CLIP

Songlong Xing, Zhengyu Zhao, N. Sebe
3/1/2025

No official code found. Best implementation: Sxing2/CLIP-Test-time-Counterattacks (42 stars, last commit 2025-06-04).

Abstract

Despite its prevalent use in image-text matching tasks in a zero-shot manner, CLIP has been shown to be highly vulnerable to adversarial perturbations added onto images. Recent studies propose to finetune the vision encoder of CLIP with adversarial samples generated on the fly, and show improved robustness against adversarial attacks on a spectrum of downstream datasets, a property termed as zero-shot robustness. In this paper, we show that malicious perturbations that seek to maximise the classification loss lead to ‘falsely stable’ images, and propose to leverage the pre-trained vision encoder of CLIP to counterattack such adversarial images during inference to achieve robustness. Our paradigm is simple and training-free, providing the first method to defend CLIP from adversarial attacks at test time, which is orthogonal to existing methods aiming to boost zero-shot adversarial robustness of CLIP. We conduct experiments across 16 classification datasets, and demonstrate stable and consistent gains compared to test-time defence methods adapted from existing adversarial robustness studies that do not rely on external networks, without noticeably impairing performance on clean images. We also show that our paradigm can be employed on CLIP models that have been adversarially finetuned to further enhance their robustness at test time. Our code is available here.

View on arXivView PDF

Code Implementations(1)

[CVPR-25🔥] Test-time Counterattacks (TTC) towards adversarial robustness of CLIP

423Shell, PythonMar 1, 20251 years ago

Similar Papers

Cite this paper

@article{xing2025clip,
  title  = {CLIP is Strong Enough to Fight Back: Test-time Counterattacks towards Zero-shot Adversarial Robustness of CLIP},
  author = {Songlong Xing and Zhengyu Zhao and N. Sebe},
  year   = {2025},
  eprint = {2503.03613},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2503.03613},
  journal = {CVPR 2025 2025}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2503.03613.svg)](https://codeofpaper.com/paper/2503.03613)

Discussion