# segmentation

Python API: `luxonis_train.utils.segmentation`

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

## Functions

### 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)
and
[default_annotate](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/utils/annotation.md)
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]]]
```

Parameters

 * `data` (`Tensor`): The logits of shape `[C, H, W]`.
 * `binary_threshold` (`float`): The sigmoid threshold for a single channel. The function ignores it for more channels.

Returns

 * `Tensor`: The boolean masks, with the shape and the device of `data`.
