Attack-SAM: Towards Attacking Segment Anything Model With Adversarial Examples

Chenshuang Zhang, Chaoning Zhang, Taegoo Kang, Donghun Kim, Sung-Ho Bae, In So KweonarXiv 2023 · DOI

Abstract

The Segment Anything Model (SAM) represents a significant leap in promptable computer vision, offering impressive zero-shot segmentation capabilities. However, the adversarial robustness of such foundation models is not yet well understood. This paper introduces Attack-SAM, a framework that demonstrates SAM's high vulnerability to adversarial perturbations. We propose a novel ClipMSE loss to effectively generate adversarial examples that can either completely remove predicted masks or force the model to generate "hallucinated" shapes. Our results show that SAM's architecture inherits the vulnerabilities of its underlying Vision Transformer (ViT) components, posing a challenge for the deployment of robust foundation models in security-sensitive applications.

Introduction

Foundation models like GPT have transformed Natural Language Processing, and Meta’s Segment Anything Model (SAM) aims to do the same for Computer Vision. SAM is designed to be "promptable," allowing users to segment objects using points, boxes, or text. While powerful, deep neural networks are known to be susceptible to adversarial examples—inputs modified by tiny, often imperceptible perturbations that lead to incorrect model outputs.

Existing adversarial research primarily focuses on classification tasks. SAM presents a unique challenge because it is a prompt-based segmentation model. This study investigates whether SAM's unique architecture provides any inherent protection against adversarial attacks and introduces the Attack-SAM framework to evaluate its robustness.

Methodology: The Attack-SAM Framework

The authors focus on two primary attack objectives: Mask Removal (untargeted) and Mask Generation (targeted).

ClipMSE Loss

A key technical contribution is the ClipMSE loss. In standard segmentation attacks using Mean Squared Error (MSE), the optimization process continues to update pixels even after they have been successfully pushed to the background. This leads to inefficient gradient use. ClipMSE addresses this by introducing a negative threshold ($Neg_{th}$) and clipping the loss once a pixel's prediction is sufficiently low. This focuses the attack on "stubborn" pixels that the model still identifies as part of the foreground mask.

Attack Strategies

  • Standard Algorithms: The framework adapts the Fast Gradient Sign Method (FGSM) and Projected Gradient Descent (PGD) to work with the ClipMSE loss.
  • Cross-Prompt Transfer: To create "prompt-agnostic" attacks, perturbations are generated by simultaneously attacking $K$ random prompts. This ensures the adversarial image remains effective regardless of where a user eventually clicks.
  • Cross-Task Transfer: The study also explores whether adversarial noise designed for classification models (like ViT) can transfer to SAM.

Experimental Results

The effectiveness of Attack-SAM was evaluated on the SA-1B dataset and standard SAM demo images.

Mask Removal and Qualitative Impact

Using PGD-10 with ClipMSE loss, the researchers successfully reduced the mean Intersection over Union (mIoU) from 1.0 (clean) to 0.0487, effectively erasing the predicted masks.

Figure 3: Qualitative comparison of SAM's performance on clean images versus adversarial examples generated by FGSM and PGD. The masks are significantly degraded or entirely removed in the attacked versions.

As shown in Figure 3, both FGSM and PGD attacks significantly degrade the quality of the segmentation masks. While FGSM introduces noticeable noise and partial mask removal, PGD (with multiple iterations) is capable of almost entirely eliminating the model's output.

Targeted Mask Generation

Beyond simple removal, the authors demonstrated "adversarial reprogramming." By modifying the loss function to target specific geometric shapes (like circles or squares), they forced SAM to output these shapes in locations where no such objects existed in the original image. This "hallucination" occurs regardless of the user's prompt.

Transferability

The cross-prompt experiments revealed that increasing the number of source prompts ($K$) used during attack generation significantly improves success on unseen target prompts. For $K=400$, the mIoU dropped to 0.0971, proving that an attacker does not need to know the user's specific interaction point to be successful.

Discussion and Limitations

While Attack-SAM is highly effective in white-box settings, some limitations remain. Cross-task attacks (from classification to segmentation) showed only partial success, suggesting a "task discrepancy" that limits universal transferability. Additionally, targeted mask generation sometimes results in small noise artifacts.

Conclusion

This research provides the first comprehensive look at the adversarial robustness of vision foundation models like SAM. The findings suggest that massive scale and prompt-based interaction do not inherently protect models from adversarial vulnerabilities. Developing robust versions of these foundation models is a critical next step for the computer vision community.

Summary updated

BibTeX
@misc{zhang2023attack,
  author = {Chenshuang Zhang and Chaoning Zhang and Taegoo Kang and Donghun Kim and Sung-Ho Bae and In So Kweon},
  title = {{Attack-SAM: Towards Attacking Segment Anything Model With Adversarial Examples}},
  year = {2023},
  eprint = {2305.00866},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.00866},
}
Figure