segment-anything-model

Segment objects in images using point, box, or mask prompts with Meta's SAM model.

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill segment-anything-model-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: segment-anything-model
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/segment-anything
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill segment-anything-model-tamagusko

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires segment-anything, transformers, torch, and includes references (resource) components.

What problem does it solve? Segmenting objects in images traditionally requires training task-specific models on labeled datasets. This Skill provides guidance for using Meta's Segment Anything Model (SAM) to segment any object in any image with zero-shot transfer, using simple point, box, or mask prompts instead of custom training. ## Core Features & Use Cases - Interactive Prompt-Based Segmentation: Generate masks from foreground/background points, bounding boxes, or previous masks using SamPredictor, with iterative refinement support. - Automatic Mask Generation: Produce all object masks in an image at once with SamAutomaticMaskGenerator, with tunable quality, stability, and density thresholds. - Deployment & Integration: Export to ONNX for edge deployment, use HuggingFace Transformers, build FastAPI/Gradio services, or extend with Grounded SAM for text-prompted segmentation and SAM 2 for video. - Use Case: Building an annotation tool where a user clicks on an object and instantly receives a high-quality segmentation mask, or generating training data for downstream vision models from unlabeled images. ## Quick Start Use the segment-anything skill to segment the object at a clicked point in my image and return the best mask with its quality score.

Frequently Asked Questions about segment-anything-model

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I segment an object in an image with SAM?

Load a checkpoint with sam_model_registry, create a SamPredictor, call set_image once, then predict with point coordinates and labels or a bounding box. The predict method returns masks, quality scores, and logits; select the mask with the highest score.

How do I generate all object masks in an image automatically?

Use SamAutomaticMaskGenerator with your loaded SAM model and call generate on the image. Tune points_per_side, pred_iou_thresh, and stability_score_thresh to control mask density and quality, then filter results by predicted_iou or area.

SAM vs SAM 2: which should I use for video segmentation?

SAM 2 is the right choice for video because it adds a streaming memory architecture that tracks objects across frames. SAM only processes individual images and has no temporal tracking, so use it for still-image segmentation tasks.

Can SAM segment objects from a text description?

SAM alone does not accept text prompts. Combine it with GroundingDINO in a Grounded SAM pipeline: GroundingDINO converts text into bounding boxes, which SAM then uses as box prompts to produce masks.

Why does SAM run out of GPU memory during inference?

The ViT-H checkpoint requires significant VRAM, especially with large images. Switch to the smaller ViT-B model, resize images to a maximum dimension, call torch.cuda.empty_cache between images, or convert the model to half precision.

When should I not use SAM for segmentation?

Avoid SAM when you need class labels, since it produces class-agnostic masks. Use YOLO or Detectron2 for real-time detection with categories, Mask2Former for semantic or panoptic segmentation, and SAM 2 for video tasks.