Open Source
Explore the latest AI open-source projects from GitHub and HuggingFace.
Explore the latest AI open-source projects from GitHub and HuggingFace.
Object segmentation and tracking in video has long been a two-step problem: first, detect what you care about; then, follow it across frames. These steps were historically performed by separate models with incompatible interfaces, requiring bespoke glue code and careful post-processing. Grounded SAM 2, developed by IDEA-Research, collapses this pipeline into a unified, text-driven system capable of finding, segmenting, and tracking any object in a video using only a natural language description.
Built on top of Meta's Segment Anything Model 2 (SAM 2) and IDEA-Research's own Grounding DINO family of open-vocabulary detectors, Grounded SAM 2 has accumulated over 3,300 stars since its release and has become a go-to foundation for video understanding research and production applications. The project's philosophy emphasizes simplicity: rather than introducing new model weights, it assembles existing state-of-the-art models into a clean, composable pipeline with minimal implementation overhead.
The system is structured as a three-stage pipeline:
Grounded SAM 2 supports multiple detector backends for the initial localization step:
| Detector | Type | Access |
|---|---|---|
| Grounding DINO | Open-source, local | Free |
| Grounding DINO 1.5 / 1.6 | API-based, higher accuracy | Cloud API |
| Florence-2 | Open-source, local | Free |
| DINO-X | API-based, strongest generalization | Cloud API |
Each detector takes a natural language prompt (e.g., "person carrying a red bag") and returns bounding boxes with confidence scores. Florence-2 is particularly noteworthy as it supports dense region captioning — it can describe what it sees without requiring a specific query, enabling fully automated annotation workflows.
Detected bounding boxes are fed as prompts to SAM 2, which produces pixel-precise segmentation masks. SAM 2's architecture extends the original SAM with a streaming memory mechanism that maintains object state across video frames, enabling robust tracking even through occlusions, fast motion, and scene changes.
The SAM 2.1 update, supported in this repository, brought significant improvements in mask quality on challenging boundaries and thin structures — critical for applications like human pose analysis and medical imaging.
The framework integrates with Roboflow's supervision library for rich annotation rendering, supporting:
For single-image tasks, the pipeline accepts a text prompt and returns annotated images with bounding boxes and masks for all matching objects. A typical use case is automated dataset labeling: given an unlabeled image collection and a class list, Grounded SAM 2 can produce COCO-format annotations in a fraction of the time required for manual annotation.
The most powerful capability is end-to-end video tracking from text prompts. The workflow:
This workflow has proven particularly valuable for sports analytics, wildlife monitoring, and retail foot traffic analysis — domains where manual video annotation is prohibitively expensive.
A key limitation of most object detection systems is degraded performance on very large images with small objects. Grounded SAM 2 integrates SAHI (Slicing Aided Hyper Inference), which:
This makes the system viable for satellite imagery analysis, microscopy, and drone footage — applications where target objects may occupy fewer than 32×32 pixels in a full-resolution frame.
The Florence-2 integration enables a zero-shot auto-labeling capability: Florence-2 generates dense captions for image regions, which are then used as grounding queries to SAM 2. The resulting masks can be exported directly to training datasets, closing the loop between unlabeled data collection and model training without any human annotation.
Installation requires SAM 2 and the appropriate detector:
pip install torch torchvision
pip install git+https://github.com/IDEA-Research/Grounded-SAM-2
pip install supervision
A minimal image segmentation example:
from grounded_sam2 import GroundedSAM2
model = GroundedSAM2(detector="grounding_dino", sam_variant="sam2.1_hiera_large")
results = model.predict(image="photo.jpg", text="person . car . bicycle")
results.visualize(output_path="annotated.jpg")
For video tracking, results are output as annotated video files with frame-level JSON metadata containing object IDs, class labels, bounding boxes, and mask RLEs.
| Task | Speed (A100) | Memory |
|---|---|---|
| Image segmentation (Grounding DINO + SAM 2 Large) | ~2 FPS | ~10 GB |
| Video tracking (1080p, SAM 2 Large) | ~8 FPS | ~8 GB |
| High-res with SAHI (4K, 4×4 tiles) | ~0.4 FPS | ~12 GB |
Grounded SAM 2 is well-suited for:
For anyone working on video AI in 2026, Grounded SAM 2 represents the most accessible path to production-quality, text-driven object tracking without training a single new model.