class documentation
class SegmentationAnnotation(Annotation):
Known subclasses: luxonis_ml.data.datasets.InstanceSegmentationAnnotation
Run-length encoded segmentation mask.
The encoded mask uses COCO-style run-length encoding.
This class support parsing segmentation masks from multiple input formats:
- Run-length encoding (RLE) directly as a list of counts or as a byte string.
- Binary mask arrays as numpy arrays or saved as .npy or .png files.
- Polygons as lists of normalized points together with the image width and height.
Example
>>> rle = SegmentationAnnotation( ... height=4, ... width=4, ... counts=b'11213ON0' ... ) >>> mask = SegmentationAnnotation( ... mask=np.array( ... [ ... [0, 1, 0, 0], ... [1, 1, 0, 0], ... [0, 0, 0, 0], ... [0, 0, 1, 1], ... ] ... ) ... ) >>> np.array_equal(rle.to_numpy(), mask.to_numpy()) True
Note
When providing the RLE as a list of counts instead of encoded bytes make sure the counts follow FORTRAN (column-major) order as expected by the COCO RLE format.
| Static Method | combine |
Combine segmentation annotations into class masks. |
| Method | to |
Convert the segmentation annotation to a binary mask. |
| Instance Variable | counts |
Run-length encoded mask data. |
| Instance Variable | height |
The height of the segmentation mask. |
| Instance Variable | width |
The width of the segmentation mask. |
| Class Method | _validate |
Undocumented |
| Class Method | _validate |
Undocumented |
| Class Method | _validate |
Undocumented |
| Static Method | _clip |
Undocumented |
| Static Method | _numpy |
Undocumented |
| Method | _serialize |
Undocumented |
@staticmethod
@override
def combine_to_numpy(annotations: @override
list[ SegmentationAnnotation], classes: list[ int], n_classes: int) -> np.ndarray:
¶
overridden in
luxonis_ml.data.datasets.InstanceSegmentationAnnotationCombine segmentation annotations into class masks.
Note
In case of overlapping annotations, the first mask in the list takes precedence.
| Parameters | |
annotations:list[ | Segmentation annotations to combine. |
classes:list[ | Class IDs associated with the annotations. |
nint | Total number of known classes. |
| Returns | |
np.ndarray | Combined semantic segmentation masks of shape (C, H, W). |
@model_validator( mode='before')
@classmethod
def _validate_mask(cls, values: @classmethod
dict[ str, Any]) -> dict[ str, Any]:
¶
Undocumented
@model_validator( mode='before')
@classmethod
def _validate_polyline(cls, values: @classmethod
dict[ str, Any]) -> dict[ str, Any]:
¶
Undocumented
@model_validator( mode='before')
@classmethod
def _validate_rle(cls, values: @classmethod
dict[ str, Any]) -> dict[ str, Any]:
¶
Undocumented