annotation module

class datumaro.components.annotation.AnnotationType(value)[source]

Bases: enum.Enum

An enumeration.

label = 1
mask = 2
points = 3
polygon = 4
polyline = 5
bbox = 6
caption = 7
cuboid_3d = 8
datumaro.components.annotation.NO_GROUP = 0

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

class datumaro.components.annotation.Annotation(*, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0)[source]

Bases: object

A base annotation class.

Derived classes must define the ‘_type’ class variable with a value from the AnnotationType enum.

Describes an identifier of the annotation. Is not required to be unique within DatasetItem annotations or dataset.

id: int

Arbitrary annotation-specific attributes. Typically, includes metainfo and properties that are not covered by other fields. If possible, try to limit value types of values by the simple builtin types (int, float, bool, str) to increase compatibility with different formats. There are some established names for common attributes like:

  • “occluded” (bool)

  • “visible” (bool)

Possible dataset attributes can be described in Categories.attributes.

attributes: Dict[str, Any]

Annotations can be grouped, which means they describe parts of a single object. The value of 0 means there is no group.

group: int
property type: datumaro.components.annotation.AnnotationType
wrap(**kwargs)[source]

Returns a modified copy of the object

__eq__(other)

Method generated by attrs for class Annotation.

__init__(*, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0) None

Method generated by attrs for class Annotation.

class datumaro.components.annotation.Categories(*, attributes: Set[str] = _Nothing.NOTHING)[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.

Describes the list of possible annotation-type specific attributes in a dataset.

attributes: Set[str]
__eq__(other)

Method generated by attrs for class Categories.

__init__(*, attributes: Set[str] = _Nothing.NOTHING) None

Method generated by attrs for class Categories.

class datumaro.components.annotation.LabelCategories(items: List[str] = _Nothing.NOTHING, *, attributes: Set[str] = _Nothing.NOTHING)[source]

Bases: datumaro.components.annotation.Categories

items: List[str]
classmethod from_iterable(iterable: Iterable[Union[str, Tuple[str], Tuple[str, str], Tuple[str, str, List[str]]]]) datumaro.components.annotation.LabelCategories[source]

Creates a LabelCategories from iterable.

Parameters

iterable – This iterable object can be: - a list of str - will be interpreted as list of Category names - a list of positional arguments - will generate Categories with these arguments

Returns: a LabelCategories object

add(name: str, parent: Optional[str] = None, attributes: Optional[Set[str]] = None) int[source]
find(name: str) Tuple[Optional[int], Optional[Category]][source]
__getitem__(idx: int) Category[source]
__contains__(value: Union[int, str]) bool[source]
__len__() int[source]
__iter__() Iterator[Category][source]
__eq__(other)

Method generated by attrs for class LabelCategories.

__init__(items: List[str] = _Nothing.NOTHING, *, attributes: Set[str] = _Nothing.NOTHING) None

Method generated by attrs for class LabelCategories.

class datumaro.components.annotation.Label(label, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0)[source]

Bases: datumaro.components.annotation.Annotation

label: int
__eq__(other)

Method generated by attrs for class Label.

__init__(label, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0) None

Method generated by attrs for class Label.

datumaro.components.annotation.RgbColor

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Tuple[int, int, int]

datumaro.components.annotation.Colormap

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Dict[int, Tuple[int, int, int]]

class datumaro.components.annotation.MaskCategories(colormap: Dict[int, Tuple[int, int, int]] = _Nothing.NOTHING, inverse_colormap: Optional[Dict[Tuple[int, int, int], int]] = None, *, attributes: Set[str] = _Nothing.NOTHING)[source]

Bases: datumaro.components.annotation.Categories

Describes a color map for segmentation masks.

classmethod generate(size: int = 255, include_background: bool = True) datumaro.components.annotation.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.

colormap: Colormap
property inverse_colormap: Dict[Tuple[int, int, int], int]
__contains__(idx: int) bool[source]
__getitem__(idx: int) Tuple[int, int, int][source]
__len__() int[source]
__eq__(other)[source]

Method generated by attrs for class Categories.

__init__(colormap: Dict[int, Tuple[int, int, int]] = _Nothing.NOTHING, inverse_colormap: Optional[Dict[Tuple[int, int, int], int]] = None, *, attributes: Set[str] = _Nothing.NOTHING) None

Method generated by attrs for class MaskCategories.

class datumaro.components.annotation.Mask(image, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0)[source]

Bases: datumaro.components.annotation.Annotation

Represents a 2d single-instance binary segmentation mask.

label: Optional[int]
z_order: int
property image: numpy.ndarray
as_class_mask(label_id: Optional[int] = None) numpy.ndarray[source]

Produces a class index mask. Mask label id can be changed.

as_instance_mask(instance_id: int) numpy.ndarray[source]

Produces a instance index mask.

get_area() int[source]
get_bbox() Tuple[int, int, int, int][source]

Computes the bounding box of the mask.

Returns: [x, y, w, h]

paint(colormap: Dict[int, Tuple[int, int, int]]) numpy.ndarray[source]

Applies a colormap to the mask and produces the resulting image.

__eq__(other)[source]

Method generated by attrs for class Annotation.

__init__(image, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0) None

Method generated by attrs for class Mask.

class datumaro.components.annotation.RleMask(rle, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0)[source]

Bases: datumaro.components.annotation.Mask

An RLE-encoded instance segmentation mask.

rle = attrib()

uses pycocotools RLE representation

CompiledMaskImage

2d of integers (of different precision)

property image: numpy.ndarray
property rle
get_area() int[source]
get_bbox() Tuple[int, int, int, int][source]

Computes the bounding box of the mask.

Returns: [x, y, w, h]

__eq__(other)[source]

Method generated by attrs for class Annotation.

__init__(rle, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0) None

Method generated by attrs for class RleMask.

class datumaro.components.annotation.CompiledMask(class_mask: Union[None, numpy.ndarray, Callable[[], numpy.ndarray]] = None, instance_mask: Union[None, numpy.ndarray, Callable[[], numpy.ndarray]] = None)[source]

Bases: object

Represents class- and instance- segmentation masks with all the instances (opposed to single-instance masks).

static from_instance_masks(instance_masks: Iterable[datumaro.components.annotation.Mask], instance_ids: Optional[Iterable[int]] = None, instance_labels: Optional[Iterable[int]] = None) datumaro.components.annotation.CompiledMask[source]

Joins instance masks into a single mask. Masks are sorted by z_order (ascending) prior to merging.

Parameters
  • instance_ids – Instance id values for the produced instance mask. By default, mask positions are used.

  • instance_labels – Instance label id values for the produced class mask. By default, mask labels are used.

__init__(class_mask: Union[None, numpy.ndarray, Callable[[], numpy.ndarray]] = None, instance_mask: Union[None, numpy.ndarray, Callable[[], numpy.ndarray]] = None)[source]
property class_mask: Optional[numpy.ndarray]
property instance_mask: Optional[numpy.ndarray]
property instance_count: int
get_instance_labels() Dict[int, int][source]

Matches the class and instance masks.

Returns: { instance id: class id }

extract(instance_id: int) numpy.ndarray[source]

Extracts a single-instance mask from the compiled mask.

lazy_extract(instance_id: int) Callable[[], numpy.ndarray][source]
class datumaro.components.annotation.PolyLine(points, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0)[source]

Bases: datumaro.components.annotation._Shape

_Shape.get_area()
_Shape.get_bbox() Tuple[float, float, float, float]

Returns [x, y, w, h]

as_polygon()[source]
get_area()[source]
__eq__(other)

Method generated by attrs for class PolyLine.

__init__(points, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0) None

Method generated by attrs for class PolyLine.

class datumaro.components.annotation.Cuboid3d(position, rotation=None, scale=None, **kwargs)[source]

Bases: datumaro.components.annotation.Annotation

label: Optional[int]
__init__(position, rotation=None, scale=None, **kwargs)[source]

Method generated by attrs for class Annotation.

property position

[x, y, z]

property rotation

[rx, ry, rz]

property scale

[sx, sy, sz]

__eq__(other)

Method generated by attrs for class Cuboid3d.

class datumaro.components.annotation.Polygon(points, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0)[source]

Bases: datumaro.components.annotation._Shape

_Shape.get_area(self)
_Shape.get_bbox(self)

Returns [x, y, w, h]

get_area()[source]
__eq__(other)

Method generated by attrs for class Polygon.

__init__(points, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0) None

Method generated by attrs for class Polygon.

class datumaro.components.annotation.Bbox(x, y, w, h, *args, **kwargs)[source]

Bases: datumaro.components.annotation._Shape

_Shape.get_area(self)
_Shape.get_bbox(self)

Returns [x, y, w, h]

__init__(x, y, w, h, *args, **kwargs)[source]

Method generated by attrs for class _Shape.

property x
property y
property w
property h
get_area()[source]
get_bbox()[source]

Returns [x, y, w, h]

as_polygon()[source]
iou(other: datumaro.components.annotation._Shape) Union[float, Literal[-1]][source]
wrap(**kwargs)[source]

Returns a modified copy of the object

__eq__(other)

Method generated by attrs for class Bbox.

class datumaro.components.annotation.PointsCategories(items: Dict[int, Category] = _Nothing.NOTHING, *, attributes: Set[str] = _Nothing.NOTHING)[source]

Bases: datumaro.components.annotation.Categories

Describes (key-)point metainfo such as point names and joints.

items: Dict[int, Category]
class Category(labels: List[str] = _Nothing.NOTHING, joints: Set[Tuple[int, int]] = _Nothing.NOTHING)[source]

Bases: object

labels
joints
__eq__(other)

Method generated by attrs for class PointsCategories.Category.

__init__(labels: List[str] = _Nothing.NOTHING, joints: Set[Tuple[int, int]] = _Nothing.NOTHING) None

Method generated by attrs for class PointsCategories.Category.

items
classmethod from_iterable(iterable: Union[Tuple[int, List[str]], Tuple[int, List[str], Set[Tuple[int, int]]]]) datumaro.components.annotation.PointsCategories[source]

Create PointsCategories from an iterable.

Parameters

elements (- iterable - An Iterable with the following) –

  • a label id

  • a list of positional arguments for Categories

Returns

PointsCategories object

Return type

PointsCategories

add(label_id: int, labels: Optional[Iterable[str]] = None, joints: Optional[Iterable[Tuple[int, int]]] = None)[source]
__contains__(idx: int) bool[source]
__getitem__(idx: int) Category[source]
__len__() int[source]
__eq__(other)

Method generated by attrs for class PointsCategories.

__init__(items: Dict[int, Category] = _Nothing.NOTHING, *, attributes: Set[str] = _Nothing.NOTHING) None

Method generated by attrs for class PointsCategories.

class datumaro.components.annotation.Points(points, visibility: Optional[List[bool]] = None, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0)[source]

Bases: datumaro.components.annotation._Shape

Represents an ordered set of points.

_Shape.get_area(self)
_Shape.get_bbox(self)

Returns [x, y, w, h]

class Visibility(value)[source]

Bases: enum.Enum

An enumeration.

absent = 0
hidden = 1
visible = 2
visibility
get_area()[source]
get_bbox()[source]

Returns [x, y, w, h]

__eq__(other)

Method generated by attrs for class Points.

__init__(points, visibility: Optional[List[bool]] = None, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, label=None, z_order: int = 0) None

Method generated by attrs for class Points.

class datumaro.components.annotation.Caption(caption, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0)[source]

Bases: datumaro.components.annotation.Annotation

Represents arbitrary text annotations.

caption
__eq__(other)

Method generated by attrs for class Caption.

__init__(caption, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0) None

Method generated by attrs for class Caption.