Visual Prompting for Adversarial Robustness

Aochuan Chen, Peter Lorenz, Yuguang Yao, Pin-Yu Chen, Sijia Liu

TL;DR

Researchers have developed Class-wise Adversarial Visual Prompting (C-AVP), a "plug-and-play" method to shield pre-trained AI models from adversarial attacks at test time. By adding specific, learned pixel patterns (prompts) to input images, they achieved a 42x inference speedup over traditional test-time defenses while significantly boosting both standard and robust accuracy compared to previous prompting methods.

What Problem Does This Paper Address?

Deep learning models are notoriously fragile; small, intentional perturbations to an image (adversarial attacks) can trick a model into misclassifying a "dog" as a "cat." While Adversarial Training (AT) is the gold standard for defense, it is computationally expensive and requires retraining the entire model from scratch.

To avoid this, researchers look for "test-time" defenses that work with fixed, off-the-shelf models. One promising idea is Visual Prompting (VP)—adding a static frame of pixels around an image to help the model generalize. However, the authors found that "universal" prompts (one pattern for all images) fail miserably at defense because they lack the complexity to counter sample-specific attacks. They also tend to tank the model's accuracy on clean, non-attacked images.

Methods

The authors propose Class-wise Adversarial Visual Prompting (C-AVP). Instead of one universal prompt, they create a unique prompt for every class (e.g., one for "planes," one for "birds").

The core challenge is: How do you know which prompt to apply to an unlabeled image at test time?

If you use the "bird" prompt on a "plane" image, it might act as a "backdoor trigger," accidentally forcing the model to see a bird. To solve this, the authors developed a joint optimization strategy using three specialized loss functions:

  1. Correct Selection Loss: Ensures that when the correct prompt is applied, the model’s confidence in the true class is maximized.
  2. Backdoor Mitigation Loss: Penalizes the "backdoor effect," ensuring that applying a mismatched prompt doesn't trick the model into a wrong prediction.
  3. Coupling Loss: Ensures the "correct" prompt is significantly more influential than any "incorrect" prompt for a given image.

At test time, the system tries all class prompts in parallel (or uses a selection rule) to find the best fit, making it a "plug-and-play" addition to any fixed classifier.

Datasets

The study primarily utilizes the CIFAR-10 dataset, a standard benchmark for image classification. They evaluated their method using a pre-trained ResNet18 model. To test robustness, they used PGD (Projected Gradient Descent) attacks, which are considered a strong, standard white-box adversarial attack.

Key Insights and Ideas

  • The Failure of Universality: A single, data-agnostic prompt is too "weak" to defend against adversarial noise. Robustness requires class-specific information.
  • The Prompt-as-Backdoor Risk: The authors identified a fascinating risk: a class-wise prompt can unintentionally behave like a backdoor attack. If the "dog" prompt is too strong, it might make everything look like a dog. Their optimization specifically fights this "cross-talk" between prompts.
  • Efficiency is King: Unlike "Input Purification" defenses that require running iterative optimization for every single image at test time, C-AVP prompts are pre-calculated. Adding them to an image is nearly instantaneous.

Key Results

  • Superior Performance: C-AVP achieved 57.57% standard accuracy and ~34.75% robust accuracy. This is a massive leap over Universal AVP, which only managed 27.75% standard and 16.9% robust accuracy.
  • Massive Speedup: Compared to state-of-the-art test-time defenses like "Denoised Smoothing" or "Input Purification," C-AVP is 42x to 518x faster during inference.
  • Ablation Success: The "Backdoor Mitigation Loss" ($\mathcal{L}_{C-AVP,2}$) was found to be the most critical component; without it, the model's ability to pick the right prompt collapsed.

Limitations and Future Work

While C-AVP is a major step forward for efficient defense, it still faces a "robustness gap." Its 34.75% robust accuracy is impressive for a test-time method but still lags behind models that have undergone full, expensive adversarial training.

The authors also note that there is an inherent trade-off: gaining robustness through prompting currently results in a significant drop in standard accuracy (from ~94% down to ~57%). Future work will likely focus on closing this gap and testing the method on larger, more complex datasets like ImageNet, where managing hundreds of class-wise prompts will present a new scaling challenge.

Summary updated

Abstract

In this work, we leverage visual prompting (VP) to improve adversarial robustness of a fixed, pre-trained model at test time. Compared to conventional adversarial defenses, VP allows us to design universal (i.e., data-agnostic) input prompting templates, which have plug-and-play capabilities at test time to achieve desired model performance without introducing much computation overhead. Although VP has been successfully applied to improving model generalization, it remains elusive whether and how it can be used to defend against adversarial attacks. We investigate this problem and show that the vanilla VP approach is not effective in adversarial defense since a universal input prompt lacks the capacity for robust learning against sample-specific adversarial perturbations. To circumvent it, we propose a new VP method, termed Class-wise Adversarial Visual Prompting (C-AVP), to generate class-wise visual prompts so as to not only leverage the strengths of ensemble prompts but also optimize their interrelations to improve model robustness. Our experiments show that C-AVP outperforms the conventional VP method, with 2.1× standard accuracy gain and 2× robust accuracy gain. Compared to classical test-time defenses, C-AVP also yields a 42× inference time speedup. Code is available at https://github.com/Phoveran/vp-for-adversarial-robustness.
BibTeX
@inproceedings{chen2023visual,
  author = {Aochuan Chen and Peter Lorenz and Yuguang Yao and Pin-Yu Chen and Sijia Liu},
  title = {{Visual Prompting for Adversarial Robustness}},
  booktitle = {IEEE International Conference on Acoustics, Speech and Signal Processing},
  year = {2023},
  doi = {10.1109/icassp49357.2023.10097245},
}

Loading related content...

Figure