Registry / ai-ml / rf-sam-2

rf-sam-2

JSON →
library1.0.3pypypi✓ verified 82d ago

Roboflow-maintained package for Meta's SAM 2 (Segment Anything Model 2) for image and video segmentation. Currently version 1.0.3, updated March 2025.

pip install rf-sam-2
INSTALL
IMPORT
SIG · RF-SAM-2
R
rf-sam-2
ai-mlpythonv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GlobalHydra
from sam2 import GlobalHydra
from rf_sam_2 import SAM2
initialize_config_module
from sam2 import initialize_config_module
from rf_sam_2 import SAM2

Basic image segmentation with a single point prompt.

import torch from rf_sam_2 import SAM2 # Load model (set environment variable for API key if needed) model = SAM2.from_pretrained("sam2-hiera-large") # Predict with an image import cv2 image = cv2.imread("path/to/image.jpg") image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) with torch.inference_mode(): masks, scores, logits = model.predict(image, point_coords=[[500, 375]], point_labels=[1]) print(masks.shape, scores)
Debug
Known issues
breakingThe import path changed from 'sam2' to 'rf_sam_2' in version 1.0.0.
fix
Use 'from rf_sam_2 import SAM2' instead of 'from sam2 import SAM2'.
affects: >=1.0.0
deprecatedThe old 'segment_anything' API is not supported; use the new SAM2 classes.
fix
Replace 'sam_model_registry' with 'SAM2.from_pretrained()'.
affects: >=1.0.0
gotchaCPU inference requires setting environment variable 'SAM2_DEVICE=cpu' before import.
fix
os.environ['SAM2_DEVICE'] = 'cpu' before importing rf_sam_2.
affects: all
Upgrade
Version history
1.0.3latest on PyPI · released Feb 2, 2026
Audit
Dependencies
torchrequiredPyTorch backend required for model inference
opencv-pythonoptionalImage/video I/O utilities
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
rf-sam-2 — pip install rf-sam-2 · libregistry