datumaro.experimental.categories#

Categories definitions for the experimental dataset system.

This module provides category management functionality using standard dataclasses instead of attrs, taking inspiration from the original Categories implementation.

Classes

Categories()

A base class for annotation metainfo.

Colormap(_data, ...)

A colormap that stores index-to-color mappings and provides efficient reverse lookup via an inverse colormap property.

GroupType(value[, names, module, qualname, ...])

Types of label groups for organizing labels.

LabelCategories(labels, group_type)

Represents a group of labels with a specific group type.

MaskCategories(colormap)

Describes a color map for segmentation masks.

RgbColor(r, g, b)

RGB color representation with named fields.

class datumaro.experimental.categories.GroupType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

Types of label groups for organizing labels.

EXCLUSIVE = 0#
INCLUSIVE = 1#
to_str() str[source]#
classmethod from_str(text: str) GroupType[source]#
class datumaro.experimental.categories.Categories[source]#

Bases: object

A base class for annotation metainfo. It is supposed to include dataset-wide metainfo like available labels, label colors, label attributes etc.

class datumaro.experimental.categories.LabelCategories(labels: ~typing.List[str] = <factory>, group_type: ~datumaro.experimental.categories.GroupType = GroupType.EXCLUSIVE)[source]#

Bases: Categories

Represents a group of labels with a specific group type.

labels: List[str]#
group_type: GroupType = 0#
add(label: str) int[source]#

Add a new label.

Parameters:

label – The label name

Returns:

The index of the newly added category

Raises:

ValueError – If label already exists

find(name: str) Tuple[int | None, str | None][source]#

Find a label by name.

Parameters:

name – The label name to find

Returns:

A tuple of (index, category) or (None, None) if not found

class datumaro.experimental.categories.RgbColor(r: int, g: int, b: int)[source]#

Bases: NamedTuple

RGB color representation with named fields.

Create new instance of RgbColor(r, g, b)

r: int#

Alias for field number 0

g: int#

Alias for field number 1

b: int#

Alias for field number 2

class datumaro.experimental.categories.Colormap(_data: ~typing.Dict[int, ~datumaro.experimental.categories.RgbColor] = <factory>)[source]#

Bases: object

A colormap that stores index-to-color mappings and provides efficient reverse lookup via an inverse colormap property.

property inverse_colormap: Dict[RgbColor, int]#

Get the inverse colormap (color -> index mapping).

get(index: int, default=None)[source]#

Get color by index with default.

class datumaro.experimental.categories.MaskCategories(colormap: ~datumaro.experimental.categories.Colormap = <factory>)[source]#

Bases: Categories

Describes a color map for segmentation masks.

colormap: Colormap#
classmethod generate(size: int = 255, include_background: bool = True) MaskCategories[source]#

Generates MaskCategories with the specified size.

If include_background is True, the result will include the item

“0: (0, 0, 0)”, which is typically used as a background color.