writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
segment-anythingUse Meta Segment Anything (SAM) for prompt-based segmentation, automatic mask generation, ONNX export, browser deployment, checkpoints, optional dependencies, and troubleshooting.
Independent GitHub snapshot · Automated classification · Original documentation governs
Use this repo skill when a user asks for help with the original Segment Anything (SAM) Python package, including checkpoint setup, promptable image segmentation, automatic mask generation, ONNX export, or browser deployment.
references/setup-and-checkpoints.md before writing code or commands.scripts/check_environment.py --check-optional to verify imports and optional packages before troubleshooting deeper issues.sub-skills/prompted-segmentation/ for SamPredictor, point/box prompts, repeated prompts on one image, iterative low-resolution mask refinement, and image embedding extraction.sub-skills/automatic-mask-generation/ for SamAutomaticMaskGenerator, all-object masks, folder runs, PNG/CSV outputs, COCO RLE JSON, and AMG CLI tuning.sub-skills/onnx-and-browser/ for ONNX export, quantization, ONNXRuntime inputs, browser asset wiring, image embeddings for web demos, and SharedArrayBuffer/header issues.For package users, prefer the public install path plus explicit backend packages:
pip install git+https://github.com/facebookresearch/segment-anything.git
pip install torch torchvision
For local development against a checkout:
pip install -e .
Optional workflows need extra packages:
pip install opencv-python pycocotools matplotlib onnx onnxruntime
Install only the extras needed for the selected workflow: OpenCV for image I/O and small-region cleanup, pycocotools for COCO RLE, matplotlib for notebook-style visualization, and onnx/onnxruntime for export, validation, and quantization.
from segment_anything import SamPredictor, SamAutomaticMaskGenerator, sam_model_registry
print(sorted(sam_model_registry.keys())) # ['default', 'vit_b', 'vit_h', 'vit_l']
default is equivalent to vit_h. Checkpoint files are not bundled with the package; the user must provide the matching .pth checkpoint.
references/setup-and-checkpoints.md before selecting a model type, checkpoint, device, or optional dependency set.references/data-formats.md when handling prompt arrays, mask outputs, annotation records, or SA-1B-style JSON.references/troubleshooting.md for install/import, checkpoint, optional dependency, backend, and cross-workflow failures.references/repo-provenance.md before deciding whether this generated skill is stale for a current checkout.scripts/check_environment.py for a safe import and optional dependency diagnostic.vit_b for lower memory and faster experiments, vit_l for a larger backbone, and vit_h or default for the largest documented model.device="cuda" for real segmentation throughput when CUDA PyTorch is correctly installed; use device="cpu" for parser checks, tiny examples, or machines without GPU access.This skill distills repository evidence into bundled references and scripts. Future agents should not need to open original notebooks, demo files, or repo scripts to answer normal SAM usage questions; use the bundled sub-skills and helpers instead.