# segmentation

Python API: `luxonis_train.utils.segmentation`

Turns the raw output of a segmentation head into boolean masks.

## Functions

| Name | Description |
| --- | --- |
| [`seg_output_to_bool`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/utils/segmentation.md#segmentation-Functions-seg_output_to_bool) | Convert the segmentation logits of one image into boolean masks. |

### function `seg_output_to_bool`

```python
def seg_output_to_bool(data: Tensor, binary_threshold: float = 0.5) -> Tensor
```

Convert the segmentation logits of one image into boolean masks.

With one channel, a pixel is `True` when its sigmoid is at least `binary_threshold`. With more channels, a pixel is `True` only in
the channel with the highest logit.
[SegmentationVisualizer](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/attached_modules/visualizers/segmentation_visualizer.md#segmentation_visualizer-Classes-SegmentationVisualizer)
and
[default_annotate](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/utils/annotation.md#annotation-Functions-default_annotate)
use the masks.

> **Example**
> ```pycon
>>> import torch
>>> from luxonis_train.utils import seg_output_to_bool
>>> logits = torch.tensor([[[2.0, -1.0]], [[0.0, 3.0]]])
>>> seg_output_to_bool(logits).tolist()
[[[True, False]], [[False, True]]]
>>> seg_output_to_bool(torch.tensor([[[0.5, -0.5]]])).tolist()
[[[True, False]]]
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `data` | `Tensor` | The logits of shape `[C, H, W]`. | required |
| `binary_threshold` | `float` | The sigmoid threshold for a single channel. The function ignores it for more channels. | `0.5` |

Returns

| Type | Description |
| --- | --- |
| `Tensor` | The boolean masks, with the shape and the device of `data`. |
