AGENT SKILL

segment-anything

Use Meta Segment Anything (SAM) for prompt-based segmentation, automatic mask generation, ONNX export, browser deployment, checkpoints, optional dependencies, and troubleshooting.

License 许可
Apache-2.0
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
segment-anything
license
Apache 2.0
metadata
{ "disco-role": "operating" }
description
Use Meta Segment Anything (SAM) for prompt-based segmentation, automatic mask generation, ONNX export, browser deployment, checkpoints, optional dependencies, and troubleshooting.
disable-model-invocation
true

02 资源文件 6

03 SKILL.md 正文

Segment Anything

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.

Start Here

  1. Install the package and required backend dependencies. SAM requires Python 3.8+, PyTorch, and TorchVision; CUDA is recommended for real workloads but CPU is usable for small inspections and examples.
  2. Choose a checkpoint/model pair from references/setup-and-checkpoints.md before writing code or commands.
  3. Run scripts/check_environment.py --check-optional to verify imports and optional packages before troubleshooting deeper issues.
  4. Route the user request to the narrowest sub-skill below.

Route by Task

  • Use sub-skills/prompted-segmentation/ for SamPredictor, point/box prompts, repeated prompts on one image, iterative low-resolution mask refinement, and image embedding extraction.
  • Use sub-skills/automatic-mask-generation/ for SamAutomaticMaskGenerator, all-object masks, folder runs, PNG/CSV outputs, COCO RLE JSON, and AMG CLI tuning.
  • Use sub-skills/onnx-and-browser/ for ONNX export, quantization, ONNXRuntime inputs, browser asset wiring, image embeddings for web demos, and SharedArrayBuffer/header issues.

Installation Pattern

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.

Minimal Import Check

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.

Shared References and Scripts

  • Read references/setup-and-checkpoints.md before selecting a model type, checkpoint, device, or optional dependency set.
  • Read references/data-formats.md when handling prompt arrays, mask outputs, annotation records, or SA-1B-style JSON.
  • Read references/troubleshooting.md for install/import, checkpoint, optional dependency, backend, and cross-workflow failures.
  • Read references/repo-provenance.md before deciding whether this generated skill is stale for a current checkout.
  • Run scripts/check_environment.py for a safe import and optional dependency diagnostic.

Common Decisions

  • Use vit_b for lower memory and faster experiments, vit_l for a larger backbone, and vit_h or default for the largest documented model.
  • Prefer 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.
  • Use prompted segmentation when the user has object hints; use automatic mask generation when the user wants proposal masks for every object.
  • Use ONNX only for the lightweight prompt/mask-decoder path; image embeddings still come from the SAM image encoder in Python and must match the exported checkpoint/model type.

Self-Containment Notes

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.

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-triton-opt

Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-solve

END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-skill

PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-pattern-fusion

Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-orchestrate

Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-feedback

Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).

★ 351