Segment an image (SAM 2 / Grounded-SAM)
replicate_segmentGenerate segmentation masks from images using point, box, or text prompts. Supports auto-masking with SAM 2 and text-prompted segmentation with Grounded-SAM.
Instructions
Produce a segmentation mask of an image. Use SAM 2 for point/box-prompt masks (auto-mask everything when no prompt given) or Grounded-SAM for text-prompt masking like "the red car".
DISPLAY REQUIREMENT — embed the mask result inline using one of the three blocks printed by the tool.
Args:
image (URL): Source image.
prompt (string, optional): Text prompt for grounded segmentation. Required for grounded-sam.
model (default "sam-2"): Curated (sam-2, grounded-sam) or "owner/name".
extra_input (object, optional): SAM-specific tuning (e.g. {points_per_side: 32}).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | Yes | URL of the image to segment. | |
| model | No | Segmentation model. Curated: sam-2, grounded-sam. Or "owner/name". | sam-2 |
| prompt | No | Text-prompt for grounded segmentation (e.g. 'the red car'). Required for grounded-sam. | |
| download | No | ||
| timeout_ms | No | Max ms to wait for the prediction. If exceeded, returns the prediction ID so you can poll via replicate_get_prediction. Default: 300000 (5min). | |
| extra_input | No | Model-specific extras (e.g. {points_per_side: 32} for SAM 2 auto-mask). |