# fastsam

Python API: `depthai_nodes.node.parsers.fastsam`

## Classes

| Name | Description |
| --- | --- |
| [`FastSAMParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser) | Parser class for parsing the output of the FastSAM model. |

### class `FastSAMParser`

```python
class FastSAMParser(BaseParser)
```

Parser class for parsing the output of the FastSAM model.

> **Note**
> Emits `dai.SegmentationMask` messages. dai.SegmentationMask message containing the resulting segmentation masks given the prompt.

Attributes

| Name | Description |
| --- | --- |
| `bbox` | Bounding box. |
| `conf_threshold` | Confidence score threshold for detected objects. |
| `iou_threshold` | Non-maximum suppression threshold. |
| `mask_conf` | Mask confidence threshold. |
| `mask_outputs` | Names of the mask outputs. |
| `n_classes` | Number of classes in the model. |
| `point_label` | Point label. |
| `points` | Points. |
| `prompt` | Prompt type. |
| `protos_output` | Name of the protos output. |
| `yolo_outputs` | Names of the YOLO outputs. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-compute) | Compute parser results from extracted tensors without sending messages. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-emit) | Create a `dai.SegmentationMask` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-extract) | Select and dequantize the model tensors needed for parsing. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setBoundingBox`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setBoundingBox) | Sets the bounding box. |
| [`setConfidenceThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setConfidenceThreshold) | Sets the confidence score threshold. |
| [`setIouThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setIouThreshold) | Sets the intersection over union threshold. |
| [`setMaskConfidence`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setMaskConfidence) | Sets the mask confidence threshold. |
| [`setMaskOutputs`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setMaskOutputs) | Sets the mask outputs. |
| [`setNumClasses`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setNumClasses) | Sets the number of classes in the model. |
| [`setPointLabel`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setPointLabel) | Sets the point label. |
| [`setPoints`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setPoints) | Sets the points. |
| [`setPrompt`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setPrompt) | Sets the prompt type. |
| [`setProtosOutput`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setProtosOutput) | Sets the protos output. |
| [`setYoloOutputs`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/fastsam.md#fastsam-Classes-FastSAMParser-setYoloOutputs) | Sets the YOLO outputs. |

#### method `__init__`

```python
def __init__(
    conf_threshold: float = 0.5,
    n_classes: int = 1,
    iou_threshold: float = 0.5,
    mask_conf: float = 0.5,
    prompt: str = 'everything',
    points: tuple[int, int] | None = None,
    point_label: int | None = None,
    bbox: tuple[int, int, int, int] | None = None,
    yolo_outputs: list[str] = None,
    mask_outputs: list[str] = None,
    protos_output: str = 'protos_output',
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `conf_threshold` | `float` | The confidence threshold for the detections | `0.5` |
| `n_classes` | `int` | The number of classes in the model | `1` |
| `iou_threshold` | `float` | The intersection over union threshold | `0.5` |
| `mask_conf` | `float` | The mask confidence threshold | `0.5` |
| `prompt` | `str` | The prompt type | `'everything'` |
| `points` | `tuple[int, int] | None` | The points | `None` |
| `point_label` | `int | None` | The point label | `None` |
| `bbox` | `tuple[int, int, int, int] | None` | The bounding box | `None` |
| `yolo_outputs` | `list[str]` | The YOLO outputs | `None` |
| `mask_outputs` | `list[str]` | The mask outputs | `None` |
| `protos_output` | `str` | The protos output | `'protos_output'` |

#### method `build`

```python
def build(head_config: dict[str, Any]) -> FastSAMParser
```

Configures the parser.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `head_config` | `dict[str, Any]` | The head configuration for the parser. | required |

Returns

| Type | Description |
| --- | --- |
| `FastSAMParser` | The parser object with the head configuration set. |

#### static method `compute`

```python
def compute(
    outputs_values: list[np.ndarray],
    masks_outputs_values: list[np.ndarray],
    protos_output: np.ndarray,
    protos_len: int,
    *,
    conf_threshold: float,
    n_classes: int,
    iou_threshold: float,
    mask_conf: float,
    prompt: str,
    points: tuple[int, int] | None,
    point_label: int | None,
    bbox: tuple[int, int, int, int] | None,
) -> tuple[np.ndarray, int]
```

Compute parser results from extracted tensors without sending messages.

> **Note**
> Uses [depthai_nodes.node.parsers.utils.fastsam.compute_fastsam_mask](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/fastsam.md#fastsam-Functions-compute_fastsam_mask); see that helper for tensor layout and validation details.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `outputs_values` | `list[np.ndarray]` | Detection tensors ordered by output head. | required |
| `masks_outputs_values` | `list[np.ndarray]` | Mask coefficient tensors ordered to match the detection heads. | required |
| `protos_output` | `np.ndarray` | Batched prototype tensor with shape `(1, channels, height, width)`. | required |
| `protos_len` | `int` | Number of prototype channels used by each mask coefficient vector. | required |
| `conf_threshold` | `float` | Minimum detection confidence used to filter candidates. | required |
| `n_classes` | `int` | Number of object classes encoded in the detection tensors. | required |
| `iou_threshold` | `float` | Intersection-over-union threshold for non-maximum suppression. | required |
| `mask_conf` | `float` | Probability threshold used to binarize mask logits. | required |
| `prompt` | `str` | Mask selection mode: `"everything"`, `"bbox"`, or `"point"`. | required |
| `points` | `tuple[int, int] | None` | Prompt point in image pixel coordinates for point selection. | required |
| `point_label` | `int | None` | Point-prompt label used to include or exclude matching masks. | required |
| `bbox` | `tuple[int, int, int, int] | None` | Bounding-box prompt in image pixel coordinates. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, int]` | A pair of the merged instance mask and the number of selected masks. No selected masks produces a background mask with value -1 and count 0. |

#### method `emit`

```python
def emit(output: dai.NNData, results_masks: np.ndarray, mask_count: int)
```

Create a `dai.SegmentationMask` message and send it on `out`.

Copies source timestamps and sequence number, and carries the source image transformation when present.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |
| `results_masks` | `np.ndarray` | Merged instance mask returned by `compute()`. | required |
| `mask_count` | `int` | Number of selected masks, used for logging. | required |

#### method `extract`

```python
def extract(
    output: dai.NNData,
) -> tuple[list[np.ndarray], list[np.ndarray], np.ndarray, int]
```

Select and dequantize the model tensors needed for parsing.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[list[np.ndarray], list[np.ndarray], np.ndarray, int]` | Detection heads in lexical layer-name order, mask coefficient heads, prototype tensor, and prototype channel count; arrays are dequantized float32 in NCHW order. |

#### method `run`

```python
def run()
```

Read queued network outputs, parse them, and emit results while running.

The pipeline invokes this processing loop. It exits when the input queue closes or the node stops.

#### method `setBoundingBox`

```python
def setBoundingBox(bbox: tuple[int, int, int, int])
```

Sets the bounding box.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bbox` | `tuple[int, int, int, int]` | The bounding box | required |

#### method `setConfidenceThreshold`

```python
def setConfidenceThreshold(threshold: float)
```

Sets the confidence score threshold.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `threshold` | `float` | Confidence score threshold. | required |

#### method `setIouThreshold`

```python
def setIouThreshold(iou_threshold: float)
```

Sets the intersection over union threshold.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `iou_threshold` | `float` | The intersection over union threshold. | required |

#### method `setMaskConfidence`

```python
def setMaskConfidence(mask_conf: float)
```

Sets the mask confidence threshold.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `mask_conf` | `float` | The mask confidence threshold. | required |

#### method `setMaskOutputs`

```python
def setMaskOutputs(mask_outputs: list[str])
```

Sets the mask outputs.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `mask_outputs` | `list[str]` | The mask outputs | required |

#### method `setNumClasses`

```python
def setNumClasses(n_classes: int)
```

Sets the number of classes in the model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `n_classes` | `int` | The number of classes in the model. | required |

#### method `setPointLabel`

```python
def setPointLabel(point_label: int)
```

Sets the point label.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `point_label` | `int` | The point label | required |

#### method `setPoints`

```python
def setPoints(points: tuple[int, int])
```

Sets the points.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `points` | `tuple[int, int]` | The points | required |

#### method `setPrompt`

```python
def setPrompt(prompt: str)
```

Sets the prompt type.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `prompt` | `str` | The prompt type | required |

#### method `setProtosOutput`

```python
def setProtosOutput(protos_output: str)
```

Sets the protos output.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `protos_output` | `str` | The protos output | required |

#### method `setYoloOutputs`

```python
def setYoloOutputs(yolo_outputs: list[str])
```

Sets the YOLO outputs.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `yolo_outputs` | `list[str]` | The YOLO outputs | required |
