SAM2RL: Towards Reinforcement Learning Memory Control in Segment Anything Model 2

Alen Adamyan, Tomáš Čížek, Matej Straka, Klara Janouskova, Martin Schmid

TL;DR

This paper introduces SAM2RL, a novel approach that uses reinforcement learning (RL) to optimize the memory update policy of the Segment Anything Model 2 (SAM 2) for visual object tracking. By treating memory control as a sequential decision-making problem, SAM2RL achieves significant performance gains over existing heuristic-based methods, demonstrating the untapped potential of RL for enhancing video tracking.

What Problem Does This Paper Address?

Visual object tracking (VOT) is a challenging task that requires accurately following a target object across a video sequence, even when faced with occlusions, motion blur, and appearance changes. State-of-the-art models like Segment Anything Model 2 (SAM 2) leverage a memory bank to maintain temporal consistency by storing information from previous frames. However, SAM 2's fixed memory update mechanism can be suboptimal, as it doesn't account for the varying relevance of past frames to the current tracking task. While recent methods have proposed hand-crafted rules to improve these updates for specific scenarios (e.g., motion, distractors), this paper argues for a more adaptive and data-driven approach. The core problem addressed is how to dynamically and optimally manage the information stored in SAM 2's memory bank to maximize tracking performance.

Methods

The authors propose SAM2RL, which frames the SAM 2 memory update process as a reinforcement learning problem. An RL agent is trained to learn an optimal policy for deciding which incoming frame information should be stored in the memory bank and which existing memory should be replaced.

Here's a breakdown of the approach:

  • SAM 2 Architecture: The paper briefly describes SAM 2's core components: an image encoder, a memory attention mechanism that conditions the image embedding with memories from the bank, and a mask decoder to generate segmentation masks. The memory encoder then creates a new memory feature from the predicted mask and image embedding.
  • Memory Bank: SAM 2 uses a fixed-capacity memory bank (N=7) that stores the most recent frames along with the initial frame.
  • RL Formulation:
    • Environment: The SAM 2 pipeline acts as the environment.
  • Agent: An RL agent learns the memory update policy.
  • Observation: The agent observes the current state of the memory bank and the feature of the current frame.
  • Action: The agent chooses to either discard the incoming memory feature or insert it into the memory bank, replacing one of the existing N-1 memories.
  • Reward: The reward signal is directly derived from the tracking quality (mean Intersection-over-Union, IoU) on frames with a visible object, with a penalty for incorrect predictions when the object is absent. This aligns the RL agent's objective with the primary metric of the VOTS challenge.
  • Overfitting Setup: To demonstrate the upper bound of performance achievable by optimizing the memory policy, the authors train a separate RL agent for each individual video in the evaluation set. This "overfitting" setup allows them to isolate the impact of the memory update policy without the complexities of generalization.

Datasets

  • SA-V training set: Used for training the RL agents. The paper mentions it contains 64 videos.
  • VOTS challenge metrics: Used for evaluating tracking performance.

Key Insights and Ideas

  • RL as a superior alternative to hand-crafted rules: The paper strongly suggests that reinforcement learning can learn more effective memory update strategies than manually designed heuristics, which are often tailored to specific failure cases.
  • Untapped potential of SAM 2's memory bank: By optimizing the memory update policy, significant performance improvements can be achieved, indicating that the memory bank itself has more capacity for useful information than current update mechanisms fully exploit.
  • Overfitting reveals policy's true potential: Training an RL agent per video allows for a clear demonstration of how much performance can be unlocked by an ideal memory control strategy for that specific sequence, setting a high benchmark.
  • Memory bank optimization can improve tracking without modifying SAM 2's core: The proposed SAM2RL achieves gains without altering the trainable parameters of the original SAM 2, highlighting the modularity and impact of memory management.

Key Results

  • Significant performance gains: SAM2RL, in its overfitting setup, achieved a relative improvement over SAM 2 that was more than three times greater than the gains from existing heuristic methods.
  • Quantitative improvements:
    • Tracking Quality: +4.91% improvement over SAM 2.
  • Accuracy: +2.52% improvement over SAM 2.
  • Robustness: +2.33% improvement over SAM 2.
  • Comparison to baselines: SAM2RL outperformed SAM 2, SAMURAI, and DAM4SAM across all three VOTS metrics. Notably, SAMURAI underperformed SAM 2 in tracking quality in their setup.
  • Qualitative results: Visualizations show SAM2RL producing more accurate masks and successfully recovering tracking after object disappearance, where DAM4SAM failed.

Limitations and Future Work

  • Overfitting limitation: The current SAM2RL is trained to overfit individual videos. This means it does not generalize to unseen videos or datasets.
  • Memory bank capacity: Even with an optimized policy, the paper notes that SAM2RL still fails to achieve "optimal performance" in some cases, suggesting that the fixed memory bank capacity might be a limiting factor.
  • Future Work: The authors plan to scale their approach by:
  • Integrating richer observations for the RL agent.
  • Developing more suitable network architectures.
  • The ultimate goal is to learn policies that can generalize beyond the training data, pushing the state-of-the-art in video object tracking.

Summary updated

BibTeX
@inproceedings{adamyan2025sam,
  author = {Alen Adamyan and Tomáš Čížek and Matej Straka and Klara Janouskova and Martin Schmid},
  title = {{SAM2RL: Towards Reinforcement Learning Memory Control in Segment Anything Model 2}},
  booktitle = {RL4RS @ RLC},
  year = {2025},
  url = {https://openreview.net/forum?id=nikfkVtih1},
}
Figure