Vanish into Thin Air: Cross-prompt Universal Adversarial Attacks for SAM2

Ziqi Zhou, Yifan Hu, Yufei Song, Zijing Li, Shengshan Hu, Leo Yu Zhang, Dezhong Yao, Long Zheng, Hai Jin

TL;DR

While Meta’s Segment Anything Model 2 (SAM2) excels at video segmentation due to its advanced memory mechanism, its vulnerability to adversarial attacks has remained largely unexplored. This paper introduces UAP-SAM2, the first cross-prompt universal adversarial attack that disrupts SAM2's temporal consistency and frame-level semantics, causing target objects to completely "vanish into thin air" across different prompts and videos.

What Problem Does This Paper Address?

The original Segment Anything Model (SAM) revolutionized image segmentation but was highly vulnerable to adversarial perturbations—subtle, imperceptible changes to an image that fool the model. Its successor, SAM2, extends this capability to video by incorporating a memory bank that tracks object features across consecutive frames.

Interestingly, existing adversarial attacks designed for SAM fail miserably when deployed against SAM2. For instance, the state-of-the-art attack DarkSAM reduces SAM's performance by over 98%, yet only causes a minor 22% drop in SAM2.

Figure 1: An empirical study on the transferability of existing SAM attacks to SAM2

The authors identify two core reasons for this newfound resilience:

  1. Directional guidance: SAM2 locks onto a persistent, video-specific prompt representation from the first frame.
  2. Semantic entanglement: SAM2 uses historical context cached in its memory bank to correct errors in individual frames.

To break SAM2, an attack must be universal (working across different videos and frames) and cross-prompt (effective regardless of whether a user clicks a point or draws a bounding box).

Methods

The authors propose UAP-SAM2, a framework that generates a single Universal Adversarial Perturbation (UAP) capable of breaking SAM2 across diverse prompts and video sequences. It achieves this via two main strategies:

1. Target-Scanning Strategy (Cross-Prompt Transferability)

Instead of optimizing the attack against a single user prompt, the framework divides each video frame into $m$ regions and randomly assigns prompts during training. Furthermore, instead of attacking the final prompt-dependent mask directly, the attack targets the output features of the Vision Encoder, making the perturbation prompt-agnostic.

2. Dual Semantic Deviation Framework (Effectiveness)

The attack optimizes the UAP by simultaneously attacking frame-level semantics and temporal consistency using three distinct losses:

  • Semantic Confusion Attack ($J_{sa}$): Uses a binary cross-entropy loss to force the model to misinterpret foreground objects as background, and vice versa.
  • Feature Shift Attack ($J_{fa}$): Employs contrastive learning to maximize the semantic distance between the features of the original benign frame and the adversarial frame.
  • Memory Misalignment Attack ($J_{ma}$): Maximizes the feature discrepancy between consecutive adversarial frames, actively corrupting the information stored in SAM2's memory bank.
Figure 4: The framework of UAP-SAM2

Datasets

The approach was evaluated on three public video object segmentation benchmarks:

  • DAVIS 2017
  • YouTube-VOS2018
  • MOSE (Complex scenes)

To test static image segmentation, the authors also generated image-based variants (DAVIS*, YouTube*, and MOSE*) by randomly sampling static frames from the video datasets.

Key Insights and Ideas

  • First-Frame Immunity: Attacking only the first frame of a video is insufficient. SAM2’s memory attention module can recover the correct object boundaries in later frames using uncorrupted spatial features.
  • The Memory Bank Shield: Attacking a single middle frame in isolation also fails because the memory bank acts as an anchor, correcting the frame's distorted features during inference.
  • The Avalanche Effect: To successfully fool SAM2, perturbations must be applied across consecutive frames. This induces a cascading failure where the memory bank accumulates errors over time, progressively destroying temporal alignment and causing a massive drop in cosine similarity between frame features.
Figure 3: Avalanche effect

Key Results

UAP-SAM2 was tested against various model sizes (SAM2-T, SAM2-S, SAM2.1-T) and significantly outperformed existing state-of-the-art attacks:

  • Performance Drop: On the DAVIS dataset using point prompts, UAP-SAM2 reduced SAM2's mean Intersection over Union (mIoU) by over 45.79% (and up to 54.77% for its sample-wise variant).
  • Video vs. Image: The attack consistently achieved stronger degradation on video segmentation than on static image segmentation, proving its unique capability to disrupt temporal consistency.
  • Transferability: Perturbations generated on smaller models (SAM2-T) successfully transferred to larger architectures and long-video variants like Sam2long.
  • Defense Resilience: The attack remained highly effective even when subjected to common defenses like model pruning or input data pre-processing (e.g., saturation and spatter corruptions).

Limitations and Future Work

The authors note that UAP-SAM2 is tailor-made for prompt-based video segmentation foundation models. As a result, it may not directly generalize to traditional, label-fixed segmentation frameworks where outputs are tied to specific class categories rather than class-free masks. Exploring how these adversarial vulnerabilities transfer across entirely different non-SAM video architectures remains an open direction for future research.

Summary updated

Abstract

Recent studies reveal the vulnerability of the image segmentation foundation model SAM to adversarial examples. Its successor, SAM2, has attracted significant attention due to its strong generalization capability in video segmentation. However, its robustness remains unexplored, and it is unclear whether existing attacks on SAM can be directly transferred to SAM2. In this paper, we first analyze the performance gap of existing attacks between SAM and SAM2 and highlight two key challenges arising from their architectural differences: directional guidance from the prompt and semantic entanglement across consecutive frames. To address these issues, we propose UAP-SAM2, the first cross-prompt universal adversarial attack against SAM2 driven by dual semantic deviation. For cross-prompt transferability, we begin by designing a target-scanning strategy that divides each frame into k regions, each randomly assigned a prompt, to reduce prompt dependency during optimization. For effectiveness, we design a dual semantic deviation framework that optimizes a UAP by distorting the semantics within the current frame and disrupting the semantic consistency across consecutive frames. Extensive experiments on six datasets across two segmentation tasks demonstrate the effectiveness of the proposed method for SAM2. The comparative results show that UAP-SAM2 significantly outperforms state-of-the-art (SOTA) attacks by a large margin.
BibTeX
@inproceedings{zhou2025vanish,
  author = {Ziqi Zhou and Yifan Hu and Yufei Song and Zijing Li and Shengshan Hu and Leo Yu Zhang and Dezhong Yao and Long Zheng and Hai Jin},
  title = {{Vanish into Thin Air: Cross-prompt Universal Adversarial Attacks for SAM2}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=Ll29PmM3UH},
}
Figure