Scripts2026年7月6日·1 分钟阅读

SAM 2 — Segment Anything in Images and Videos by Meta

SAM 2 (Segment Anything Model 2) is Meta's foundation model for promptable visual segmentation in both images and videos, capable of producing precise object masks from points, boxes, or text prompts.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
SAM 2 Overview
直接安装命令
npx -y tokrepo@latest install 0373e7d1-7913-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

SAM 2 extends Meta's original Segment Anything Model to handle both images and videos in a unified architecture. It introduces a streaming memory mechanism that lets the model track and segment objects across video frames in real time, while maintaining the interactive prompting interface from SAM 1.

What SAM 2 Does

  • Segments any object in a single image from point, box, or mask prompts
  • Tracks and segments objects across video frames with temporal consistency
  • Produces multiple valid mask hypotheses ranked by confidence scores
  • Supports zero-shot transfer to new object categories without retraining
  • Runs interactively for annotation workflows or in batch mode for pipelines

Architecture Overview

SAM 2 uses a Hiera image encoder (a hierarchical vision transformer) to extract multi-scale features from each frame. A prompt encoder converts user inputs (points, boxes, masks) into embeddings, and a lightweight mask decoder generates segmentation masks. For video, a memory attention module maintains a memory bank of past frames and predictions, allowing the model to propagate masks forward and backward through time. The streaming design processes one frame at a time, making it practical for long videos.

Self-Hosting & Configuration

  • Install from PyPI with pip install sam-2 or clone the GitHub repository
  • Download pre-trained checkpoints (tiny, small, base+, large) from the releases page
  • Requires PyTorch 2.3+ and a CUDA-capable GPU for efficient inference
  • Configure model size via config YAML files shipped with the repo
  • Integrate into annotation tools like Label Studio or custom web UIs via the Python API

Key Features

  • Unified image and video segmentation in a single model architecture
  • Streaming memory design enables real-time video processing
  • Four model sizes from SAM 2.1 Tiny to SAM 2.1 Large for speed-accuracy tradeoffs
  • Interactive and automatic modes for both annotation and production pipelines
  • Trained on SA-V, a dataset of over 50K videos with 600K masklets

Comparison with Similar Tools

  • SAM 1 — image-only predecessor without video support; SAM 2 supersedes it with better image performance and adds video capabilities
  • XMem / Cutie — specialized video object segmentation models; SAM 2 unifies image and video in one architecture
  • GroundingDINO + SAM — combines open-vocabulary detection with segmentation; SAM 2 can be similarly composed but also handles video natively
  • YOLO-Seg — instance segmentation optimized for speed; less precise masks but faster on edge devices
  • Detectron2 — modular detection and segmentation framework; requires task-specific training unlike SAM 2's zero-shot capability

FAQ

Q: Can SAM 2 run without a GPU? A: CPU inference is possible but slow. A CUDA GPU with at least 6 GB VRAM is recommended for interactive use.

Q: Does SAM 2 understand object categories? A: No. SAM 2 segments objects based on spatial prompts, not semantic categories. Pair it with a classifier or detector for category labels.

Q: How do I segment objects in a long video? A: Provide a prompt on the first frame (or any frame), and SAM 2's memory mechanism will propagate the mask across subsequent frames automatically.

Q: What license is SAM 2 released under? A: SAM 2 is released under the Apache 2.0 license.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产