Generalizable Visual Reinforcement Learning with Segment Anything Model

Ziyu Wang, Yanjie Ze, Yifei Sun, Zhecheng Yuan, Huazhe XuarXiv 2023

Abstract

Learning policies that can generalize to unseen environments is a fundamental challenge in visual reinforcement learning (RL). While most current methods focus on acquiring robust visual representations through auxiliary supervision, pre-training, or data augmentation, the potential of modern vision foundation models remains underleveraged. In this work, we introduce Segment Anything Model for Generalizable visual RL (SAM-G), a novel framework that leverages the promptable segmentation ability of Segment Anything Model (SAM) to enhance the generalization capabilities of visual RL agents. We utilize image features from DINOv2 and SAM to find correspondence as point prompts to SAM, and then SAM produces high-quality masked images for agents directly. Evaluated across 8 DMControl tasks and 3 Adroit tasks, SAM-G significantly improves the visual generalization ability without altering the RL agents' architecture but merely their observations. Notably, SAM-G achieves 44% and 29% relative improvements on the challenging video hard setting on DMControl and Adroit respectively, compared to state-of-the-art methods.

The Challenge of Visual Generalization

Visual Reinforcement Learning (RL) agents are notorious for overfitting to their training environments. An agent trained to walk in a simple blue room often fails completely if the floor color changes or if a dynamic video plays in the background. This occurs because standard neural networks treat every pixel—including redundant environmental details—as part of the state. While humans intuitively separate a task-critical object (like a hammer) from its background (like wallpaper), RL agents struggle to distinguish between the two. Previous attempts to solve this using heavy data augmentation or auxiliary saliency losses often break down in complex, dynamic environments.

The SAM-G Framework

SAM-G addresses this by "identifying and segmenting" task-relevant objects before the RL agent even processes the observation. By providing a clean, masked image where the background is zeroed out, the agent's search space for features is drastically reduced.

The SAM-G interaction loop: SAM provides masked observations to the RL agent.

The framework operates through a multi-stage process:

  1. Identification: Using a single reference image and mask from the training environment, the system extracts "point features" using the encoders of DINOv2 (optimized for finding correspondences) and SAM.
  2. Segmentation: In new, unseen environments, the system finds the best match between stored point features and the current frame to generate "point prompts" for SAM.
  3. Refinement & Adaptation: To ensure high-quality masks, SAM-G uses an iterative refinement process and a "one-shot adaptation" technique that fine-tunes specific weights in SAM’s mask decoder to better match the target task.

To maintain practical interaction speeds for RL, SAM-G utilizes EfficientViT, making the segmentation process fast enough for real-time application.

Experimental Results

SAM-G was evaluated across 11 diverse tasks, including 8 from the DMControl suite and 3 complex Adroit dexterous manipulation tasks. Generalization was tested across four difficulty levels: Color Easy, Color Hard, Video Easy, and the highly challenging Video Hard setting.

SAM-G generalizes across diverse and complex backgrounds by producing clean masks.

Key Findings

  • State-of-the-Art Performance: SAM-G achieved a 44% relative improvement on the DMControl "Video Hard" benchmark and a 29% relative improvement on Adroit "Video Hard" compared to previous state-of-the-art methods like PIE-G.
  • Consistency: Unlike baseline methods (such as SVEA or SGQN) which perform well on easy settings but fail on hard ones, SAM-G maintained high performance across all levels of background distraction.
  • Imitation Learning: The framework also significantly outperformed baselines in Behavior Cloning for complex manipulation tasks, such as the Adroit Door and Hammer tasks.

Conclusion and Future Work

SAM-G demonstrates that leveraging the zero-shot object awareness of foundation models like SAM and DINOv2 is a powerful alternative to training agents to be invariant to noise from scratch. While the method currently requires minimal initial human supervision (one mask and a few points) and introduces some computational overhead due to the segmentation model, it represents a significant step toward robust, generalizable visual RL.

Video and code: yanjieze.com/SAM-G/

Summary updated

BibTeX
@misc{wang2023generalizable,
  author = {Ziyu Wang and Yanjie Ze and Yifei Sun and Zhecheng Yuan and Huazhe Xu},
  title = {{Generalizable Visual Reinforcement Learning with Segment Anything Model}},
  year = {2023},
  eprint = {2312.17116},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.17116},
}
Figure