> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/workflows/blocks/blocks/run-a-model/sam3.md).

# SAM 3

Run SAM3 with text prompts for zero-shot segmentation.

## v3

Run Segment Anything 3 (SAM3), a zero-shot instance segmentation model, on an image.

You can use text prompts for open-vocabulary segmentation - just specify class names and SAM3 will segment those objects in the image.

This block supports two output formats:

* **rle** (default): Returns masks in RLE (Run-Length Encoding) format, which is more memory-efficient
* **polygons**: Returns polygon coordinates for each mask

RLE format is recommended for high-resolution images or workflows with many detections.

### Type identifier

Use the following identifier in step `"type"` field: `roboflow_core/sam3@v3` to add the block as a step in your workflow.

### Properties

| **Name**               | **Type**                   | **Description**                                                                                                                                | Refs |
| ---------------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---- |
| `name`                 | `str`                      | Enter a unique identifier for this step..                                                                                                      | ❌    |
| `model_id`             | `str`                      | model version. You only need to change this for fine tuned sam3 models..                                                                       | ✅    |
| `class_names`          | `Optional[List[str], str]` | List of classes to recognise.                                                                                                                  | ✅    |
| `class_mapping`        | `Dict[str, str]`           | Maps class names in predictions to different output names. Applied after inference, e.g. {'cat': 'gato'} renames 'cat' predictions to 'gato'.. | ✅    |
| `confidence`           | `float`                    | Minimum confidence threshold for predicted masks.                                                                                              | ✅    |
| `per_class_confidence` | `List[float]`              | List of confidence thresholds per class (must match class\_names length).                                                                      | ✅    |
| `apply_nms`            | `bool`                     | Whether to apply Non-Maximum Suppression across prompts.                                                                                       | ✅    |
| `nms_iou_threshold`    | `float`                    | IoU threshold for cross-prompt NMS. Must be in \[0.0, 1.0].                                                                                    | ✅    |
| `output_format`        | `str`                      | 'rle' returns efficient RLE encoding (recommended), 'polygons' returns polygon coordinates.                                                    | ❌    |

The **Refs** column marks possibility to parametrise the property with dynamic values available in `workflow` runtime. See *Bindings* for more info.

### Runtime compatibility

`hard` - runtime `self_hosted_cpu`; execution `local` : Requires a GPU; run\_locally() loads a model that needs CUDA.

### Input and Output Bindings

The available connections depend on its binding kinds. Check what binding kinds `SAM 3` in version `v3` has.

<details>

<summary>Input and output bindings</summary>

* input
  * `images` ([*`image`*](/workflows/developer-guide/developer-guide/kinds/image.md)): The image to infer on..
  * `model_id` ([*`roboflow_model_id`*](/workflows/developer-guide/developer-guide/kinds/roboflow-model-id.md)): model version. You only need to change this for fine tuned sam3 models..
  * `class_names` (*Union\[*[*`list_of_values`*](/workflows/developer-guide/developer-guide/kinds/list-of-values.md)*,* [*`string`*](/workflows/developer-guide/developer-guide/kinds/string.md)*]*): List of classes to recognise.
  * `class_mapping` ([*`dictionary`*](/workflows/developer-guide/developer-guide/kinds/dictionary.md)): Maps class names in predictions to different output names. Applied after inference, e.g. {'cat': 'gato'} renames 'cat' predictions to 'gato'..
  * `confidence` ([*`float`*](/workflows/developer-guide/developer-guide/kinds/float.md)): Minimum confidence threshold for predicted masks.
  * `per_class_confidence` ([*`list_of_values`*](/workflows/developer-guide/developer-guide/kinds/list-of-values.md)): List of confidence thresholds per class (must match class\_names length).
  * `apply_nms` ([*`boolean`*](/workflows/developer-guide/developer-guide/kinds/boolean.md)): Whether to apply Non-Maximum Suppression across prompts.
  * `nms_iou_threshold` ([*`float`*](/workflows/developer-guide/developer-guide/kinds/float.md)): IoU threshold for cross-prompt NMS. Must be in \[0.0, 1.0].
* output
  * `predictions` (*Union\[*[*`rle_instance_segmentation_prediction`*](/workflows/developer-guide/developer-guide/kinds/rle-instance-segmentation-prediction.md)*,* [*`instance_segmentation_prediction`*](/workflows/developer-guide/developer-guide/kinds/instance-segmentation-prediction.md)*]*): Prediction with detected bounding boxes and RLE-encoded segmentation masks in form of sv.Detections(...) object if `rle_instance_segmentation_prediction` or Prediction with detected bounding boxes and segmentation masks in form of sv.Detections(...) object if `instance_segmentation_prediction`.

</details>

<details>

<summary>Example JSON definition</summary>

```json
{
	    "name": "<your_step_name_here>",
	    "type": "roboflow_core/sam3@v3",
	    "images": "$inputs.image",
	    "model_id": "sam3/sam3_final",
	    "class_names": [
	        "car",
	        "person"
	    ],
	    "class_mapping": {
	        "cat": "gato",
	        "dog": "perro"
	    },
	    "confidence": 0.3,
	    "per_class_confidence": [
	        0.3,
	        0.5,
	        0.7
	    ],
	    "apply_nms": "<block_does_not_provide_example>",
	    "nms_iou_threshold": 0.5,
	    "output_format": "rle"
	}
```

</details>

## v2

Run Segment Anything 3, a zero-shot instance segmentation model, on an image.

You can pass in boxes/predictions from other models as prompts, or use a text prompt for open-vocabulary segmentation. If you pass in box detections from another model, the class names of the boxes will be forwarded to the predicted masks.

### Type identifier

Use the following identifier in step `"type"` field: `roboflow_core/sam3@v2` to add the block as a step in your workflow.

### Properties

| **Name**               | **Type**                   | **Description**                                                           | Refs |
| ---------------------- | -------------------------- | ------------------------------------------------------------------------- | ---- |
| `name`                 | `str`                      | Enter a unique identifier for this step..                                 | ❌    |
| `model_id`             | `str`                      | model version. You only need to change this for fine tuned sam3 models..  | ✅    |
| `class_names`          | `Optional[List[str], str]` | List of classes to recognise.                                             | ✅    |
| `confidence`           | `float`                    | Minimum confidence threshold for predicted masks.                         | ✅    |
| `per_class_confidence` | `List[float]`              | List of confidence thresholds per class (must match class\_names length). | ✅    |
| `apply_nms`            | `bool`                     | Whether to apply Non-Maximum Suppression across prompts.                  | ✅    |
| `nms_iou_threshold`    | `float`                    | IoU threshold for cross-prompt NMS. Must be in \[0.0, 1.0].               | ✅    |

The **Refs** column marks possibility to parametrise the property with dynamic values available in `workflow` runtime. See *Bindings* for more info.

### Runtime compatibility

`hard` - runtime `self_hosted_cpu`; execution `local` : Requires a GPU; run\_locally() loads a model that needs CUDA.

### Input and Output Bindings

The available connections depend on its binding kinds. Check what binding kinds `SAM 3` in version `v2` has.

<details>

<summary>Input and output bindings</summary>

* input
  * `images` ([*`image`*](/workflows/developer-guide/developer-guide/kinds/image.md)): The image to infer on..
  * `model_id` ([*`roboflow_model_id`*](/workflows/developer-guide/developer-guide/kinds/roboflow-model-id.md)): model version. You only need to change this for fine tuned sam3 models..
  * `class_names` (*Union\[*[*`list_of_values`*](/workflows/developer-guide/developer-guide/kinds/list-of-values.md)*,* [*`string`*](/workflows/developer-guide/developer-guide/kinds/string.md)*]*): List of classes to recognise.
  * `confidence` ([*`float`*](/workflows/developer-guide/developer-guide/kinds/float.md)): Minimum confidence threshold for predicted masks.
  * `per_class_confidence` ([*`list_of_values`*](/workflows/developer-guide/developer-guide/kinds/list-of-values.md)): List of confidence thresholds per class (must match class\_names length).
  * `apply_nms` ([*`boolean`*](/workflows/developer-guide/developer-guide/kinds/boolean.md)): Whether to apply Non-Maximum Suppression across prompts.
  * `nms_iou_threshold` ([*`float`*](/workflows/developer-guide/developer-guide/kinds/float.md)): IoU threshold for cross-prompt NMS. Must be in \[0.0, 1.0].
* output
  * `predictions` ([`instance_segmentation_prediction`](/workflows/developer-guide/developer-guide/kinds/instance-segmentation-prediction.md)): Prediction with detected bounding boxes and segmentation masks in form of sv.Detections(...) object.

</details>

<details>

<summary>Example JSON definition</summary>

```json
{
	    "name": "<your_step_name_here>",
	    "type": "roboflow_core/sam3@v2",
	    "images": "$inputs.image",
	    "model_id": "sam3/sam3_final",
	    "class_names": [
	        "car",
	        "person"
	    ],
	    "confidence": 0.3,
	    "per_class_confidence": [
	        0.3,
	        0.5,
	        0.7
	    ],
	    "apply_nms": "<block_does_not_provide_example>",
	    "nms_iou_threshold": 0.5
	}
```

</details>

## v1

Run Segment Anything 3, a zero-shot instance segmentation model, on an image.

You can pass in boxes/predictions from other models as prompts, or use a text prompt for open-vocabulary segmentation. If you pass in box detections from another model, the class names of the boxes will be forwarded to the predicted masks.

### Type identifier

Use the following identifier in step `"type"` field: `roboflow_core/sam3@v1` to add the block as a step in your workflow.

### Properties

| **Name**      | **Type**                   | **Description**                                                          | Refs |
| ------------- | -------------------------- | ------------------------------------------------------------------------ | ---- |
| `name`        | `str`                      | Enter a unique identifier for this step..                                | ❌    |
| `model_id`    | `str`                      | model version. You only need to change this for fine tuned sam3 models.. | ✅    |
| `class_names` | `Optional[List[str], str]` | List of classes to recognise.                                            | ✅    |
| `threshold`   | `float`                    | Threshold for predicted mask scores.                                     | ✅    |

The **Refs** column marks possibility to parametrise the property with dynamic values available in `workflow` runtime. See *Bindings* for more info.

### Runtime compatibility

`hard` - runtime `self_hosted_cpu`; execution `local` : Requires a GPU; run\_locally() loads a model that needs CUDA.

### Input and Output Bindings

The available connections depend on its binding kinds. Check what binding kinds `SAM 3` in version `v1` has.

<details>

<summary>Input and output bindings</summary>

* input
  * `images` ([*`image`*](/workflows/developer-guide/developer-guide/kinds/image.md)): The image to infer on..
  * `model_id` ([*`roboflow_model_id`*](/workflows/developer-guide/developer-guide/kinds/roboflow-model-id.md)): model version. You only need to change this for fine tuned sam3 models..
  * `class_names` (*Union\[*[*`list_of_values`*](/workflows/developer-guide/developer-guide/kinds/list-of-values.md)*,* [*`string`*](/workflows/developer-guide/developer-guide/kinds/string.md)*]*): List of classes to recognise.
  * `threshold` ([*`float`*](/workflows/developer-guide/developer-guide/kinds/float.md)): Threshold for predicted mask scores.
* output
  * `predictions` ([`instance_segmentation_prediction`](/workflows/developer-guide/developer-guide/kinds/instance-segmentation-prediction.md)): Prediction with detected bounding boxes and segmentation masks in form of sv.Detections(...) object.

</details>

<details>

<summary>Example JSON definition</summary>

```json
{
	    "name": "<your_step_name_here>",
	    "type": "roboflow_core/sam3@v1",
	    "images": "$inputs.image",
	    "model_id": "sam3/sam3_final",
	    "class_names": [
	        "car",
	        "person"
	    ],
	    "threshold": 0.3
	}
```

</details>
