SAM (interactive segmentation)

SAM (Segment Anything) turns point prompts into polygon annotations.

Install

pip install "oneopen-ml-studio[sam]"
pip install git+https://github.com/facebookresearch/segment-anything.git

Note

[sam] installs PyTorch stack only. The segment-anything package is separate.

Checkpoint

Place a Meta SAM checkpoint under your models directory (default ~/.oneopen/models/):

File

Size / quality

sam_vit_b_01ec64.pth

Smaller / faster (commonly used default)

sam_vit_l_0b3195.pth

Larger

sam_vit_h_4b8939.pth

Largest

Download checkpoints from the Segment Anything repository.

Usage

  1. Open the annotator with SAM enabled in the UI.

  2. Select a class.

  3. Click positive / negative points on the object.

  4. Accept the resulting polygon (stored as source=sam).

API

POST /api/projects/{project_id}/auto-annotate/sam
Content-Type: application/json

{
  "image_id": 1,
  "class_id": 2,
  "points": [[0.4, 0.5], [0.42, 0.55]],
  "labels": [1, 1]
}

points are normalized [x, y]. labels use 1 for foreground and 0 for background (SAM convention).

Troubleshooting

Symptom

Fix

Import / module errors

Install segment-anything and torch

Checkpoint not found

Put sam_vit_b_01ec64.pth (or l/h) in ~/.oneopen/models/

Very slow

Use ViT-B on GPU; CPU is much slower