datumaro.components.annotation#

Module Attributes

Colormap

Represents { index -> color } mapping for segmentation masks

Classes

Annotation(*[, id, attributes, group, object_id])

A base annotation class.

AnnotationType(value)

An enumeration.

Annotations([iterable])

List of Annotation equipped with additional utility functions.

Bbox(x, y, w, h, *args, **kwargs)

Bbox annotation class.

Caption(caption, *[, id, attributes, group, ...])

Represents arbitrary text annotations.

Categories(*[, attributes])

A base class for annotation metainfo.

CompiledMask([class_mask, instance_mask])

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

Cuboid2D(_points, *args, **kwargs)

Cuboid2D annotation class.

Cuboid3d(position[, rotation, scale])

Cuboid3d annotation class.

DepthAnnotation(image, *[, id, attributes, ...])

Represents depth images.

Ellipse(x1, y1, x2, y2, *args, **kwargs)

Ellipse represents an ellipse that is encapsulated by a rectangle.

ExtractedMask(index_mask, index, *[, id, ...])

Mask annotation (binary mask) extracted from an index mask (integer 2D Numpy array).

FeatureVector(vector, *[, id, attributes, ...])

Method generated by attrs for class FeatureVector.

GroupType(value)

An enumeration.

HashKey(hash_key, *[, id, attributes, ...])

Method generated by attrs for class HashKey.

Label(label, *[, id, attributes, group, ...])

Method generated by attrs for class Label.

LabelCategories([items, label_groups, ...])

Method generated by attrs for class LabelCategories.

Mask(image, *[, id, attributes, group, ...])

Represents a 2d single-instance binary segmentation mask.

MaskCategories([colormap, inverse_colormap, ...])

Describes a color map for segmentation masks.

Points(points[, visibility, id, attributes, ...])

Represents an ordered set of points.

PointsCategories([items, attributes])

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

PolyLine(points, *[, id, attributes, group, ...])

PolyLine annotation class.

Polygon(points, *[, id, attributes, group, ...])

Polygon annotation class.

RleMask(rle, *[, id, attributes, group, ...])

An RLE-encoded instance segmentation mask.

RotatedBbox(cx, cy, w, h, r, *args, **kwargs)

RotatedBbox annotation class.

Shape(points, *[, id, attributes, group, ...])

Base class for shape annotations.

SuperResolutionAnnotation(image, *[, id, ...])

Represents high resolution images.

Tabular(values, *[, id, attributes, group, ...])

Represents values of target columns in a tabular dataset.

TabularCategories([items, attributes])

Describes tabular data metainfo such as column names and types.

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

Bases: IntEnum

An enumeration.

unknown = 0#
label = 1#
mask = 2#
points = 3#
polygon = 4#
polyline = 5#
bbox = 6#
caption = 7#
cuboid_3d = 8#
super_resolution_annotation = 9#
depth_annotation = 10#
ellipse = 11#
hash_key = 12#
feature_vector = 13#
tabular = 14#
rotated_bbox = 15#
cuboid_2d = 16#
class datumaro.components.annotation.Annotation(*, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#

Bases: object

A base annotation class.

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

Method generated by attrs for class Annotation.

id: int#
attributes: Dict[str, Any]#
group: int#
object_id: int#
property type: AnnotationType#
as_dict() Dict[str, Any][source]#

Returns a dictionary { field_name: value }

wrap(**kwargs)[source]#

Returns a modified copy of the object

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.

Method generated by attrs for class Categories.

attributes: Set[str]#
class datumaro.components.annotation.GroupType(value)[source]#

Bases: IntEnum

An enumeration.

EXCLUSIVE = 0#
INCLUSIVE = 1#
RESTRICTED = 2#
to_str() str[source]#
classmethod from_str(text: str) GroupType[source]#
class datumaro.components.annotation.LabelCategories(items: List[str] = _Nothing.NOTHING, label_groups: List[LabelGroup] = _Nothing.NOTHING, *, attributes: Set[str] = _Nothing.NOTHING)[source]#

Bases: Categories

Method generated by attrs for class LabelCategories.

class Category(name, parent: str = '', attributes: Set[str] = _Nothing.NOTHING)[source]#

Bases: object

Method generated by attrs for class LabelCategories.Category.

name: str#
parent: str#
attributes: Set[str]#
class LabelGroup(name, labels: List[str] = [], group_type: GroupType = GroupType.EXCLUSIVE)[source]#

Bases: object

Method generated by attrs for class LabelCategories.LabelGroup.

name: str#
labels: List[str]#
group_type: GroupType#
items: List[str]#
label_groups: List[LabelGroup]#
classmethod from_iterable(iterable: Iterable[str | Tuple[str] | Tuple[str, str] | Tuple[str, str, List[str]]]) 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: str | None = None, attributes: Set[str] | None = None) int[source]#
add_label_group(name: str, labels: List[str], group_type: GroupType) int[source]#
find(name: str) Tuple[int | None, Category | None][source]#
class datumaro.components.annotation.Label(label, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#

Bases: Annotation

Method generated by attrs for class Label.

label: int#
class datumaro.components.annotation.HashKey(hash_key: ndarray, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#

Bases: Annotation

Method generated by attrs for class HashKey.

hash_key: ndarray#
class datumaro.components.annotation.FeatureVector(vector: ndarray, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#

Bases: Annotation

Method generated by attrs for class FeatureVector.

vector: ndarray#
id: int#
attributes: Dict[str, Any]#
group: int#
object_id: int#
datumaro.components.annotation.Colormap#

Represents { index -> color } mapping for segmentation masks

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

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

Bases: Categories

Describes a color map for segmentation masks.

Method generated by attrs for class MaskCategories.

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.

colormap: Dict[int, Tuple[int, int, int]]#
property inverse_colormap: Dict[Tuple[int, int, int], int]#
class datumaro.components.annotation.Mask(image: ndarray | Callable[[], ndarray], *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1, label=None, z_order: int = 0)[source]#

Bases: Annotation

Represents a 2d single-instance binary segmentation mask.

Method generated by attrs for class Mask.

label: int | None#
z_order: int#
property image: ndarray#
as_class_mask(label_id: int | None = None, ignore_index: int = 0, dtype: dtype | None = None) ndarray[source]#

Produces a class index mask based on the binary mask.

Parameters:
  • label_id – Scalar value to represent the class index of the mask. If not specified, self.label will be used. Defaults to None.

  • ignore_index – Scalar value to fill in the zeros in the binary mask. Defaults to 0.

  • dtype – Data type for the resulting mask. If not specified, it will be inferred from the provided label_id to hold its value. For example, if label_id=255, the inferred dtype will be np.uint8. Defaults to None.

Returns:

Class index mask generated from the binary mask.

Return type:

IndexMaskImage

as_instance_mask(instance_id: int, ignore_index: int = 0, dtype: dtype | None = None) ndarray[source]#

Produces an instance index mask based on the binary mask.

Parameters:
  • instance_id – Scalar value to represent the instance id.

  • ignore_index – Scalar value to fill in the zeros in the binary mask. Defaults to 0.

  • dtype – Data type for the resulting mask. If not specified, it will be inferred from the provided label_id to hold its value. For example, if label_id=255, the inferred dtype will be np.uint8. Defaults to None.

Returns:

Instance index mask generated from the binary mask.

Return type:

IndexMaskImage

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]]) ndarray[source]#

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

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

Bases: Mask

An RLE-encoded instance segmentation mask.

Method generated by attrs for class RleMask.

property image: 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]

class datumaro.components.annotation.ExtractedMask(index_mask: ndarray | Callable[[], ndarray], index: int, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1, label=None, z_order: int = 0)[source]#

Bases: Mask

Mask annotation (binary mask) extracted from an index mask (integer 2D Numpy array).

This class can extract a binary mask with given index mask and index value. The advantage of this class is that we can create multiple binary mask but they share a single index mask source.

index_mask#

Integer 2D Numpy array. Its pixel can indicate a label id (class) or an instance id.

Type:

numpy.ndarray | Callable[[], numpy.ndarray]

index#

Integer value to extract a binary mask from the given index mask.

Type:

int

Examples

This example demonstrates how to create an ExtractedMask from a synthetic index mask, which denotes a semantic segmentation mask with binary values such as 0 for background and 1 for foreground.

>>> import numpy as np
>>> from datumaro.components.annotation import ExtractedMask
>>>
>>> index_mask = np.random.randint(low=0, high=2, size=(10, 10), dtype=np.uint8)
>>> mask1 = ExtractedMask(index_mask=index_mask, index=0, label=0)  # 0 for background
>>> mask2 = ExtractedMask(index_mask=index_mask, index=1, label=1)  # 1 for foreground
>>> np.unique(mask1.image).tolist()  # `image` property create a binary mask
np.array([0, 1])
>>> mask1.index_mask == mask2.index_mask  # They share the same source
True

Method generated by attrs for class ExtractedMask.

index_mask: ndarray | Callable[[], ndarray]#
index: int#
property image: ndarray#
class datumaro.components.annotation.CompiledMask(class_mask: None | ndarray | Callable[[], ndarray] = None, instance_mask: None | ndarray | Callable[[], 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[Mask], instance_ids: Iterable[int] | None = None, instance_labels: Iterable[int] | None = None) 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.

property class_mask: ndarray | None#
property instance_mask: ndarray | None#
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) ndarray[source]#

Extracts a single-instance mask from the compiled mask.

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

Bases: Annotation

Base class for shape annotations. This class defines the common attributes and methods for different types of shape annotations.

points#

List of float values representing the coordinates of the shape.

Type:

List[float]

label#

Optional label ID for the shape. Default is None.

Type:

Optional[int]

z_order#

Z-order of the shape, used to determine the rendering order. Default is 0.

Type:

int

get_area()[source]#

Abstract method to calculate the area of the shape.

as_polygon()[source]#

Abstract method to convert the shape into a polygon representation.

get_bbox()[source]#

Returns the bounding box of the shape as [x, y, w, h].

get_points()[source]#

Returns the points of the shape as a list of (x, y) tuples.

Method generated by attrs for class Shape.

points: List[float]#
label: int | None#
z_order: int#
get_area()[source]#

Calculate the area of the shape.

as_polygon() List[float][source]#

Convert the shape into a polygon representation.

get_bbox() Tuple[float, float, float, float][source]#

Calculate and return the bounding box of the shape.

Returns:

The bounding box as [x, y, w, h].

Return type:

Tuple[float, float, float, float]

get_points() List[Tuple[float, float]] | None[source]#

Convert and return the points of the shape as a list of (x, y) tuples.

Returns:

List of points as (x, y) tuples, or None if no points.

Return type:

Optional[List[Tuple[float, float]]]

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

Bases: Shape

PolyLine annotation class. This class represents a polyline shape, which is a series of connected line segments.

_type#

The type of annotation, set to AnnotationType.polyline.

Type:

AnnotationType

as_polygon()[source]#

Returns the points of the polyline as a polygon.

get_area()[source]#

Returns the area of the polyline, which is always 0.

Method generated by attrs for class PolyLine.

as_polygon()[source]#

Convert the shape into a polygon representation.

get_area()[source]#

Calculate the area of the shape.

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

Bases: Annotation

Cuboid3d annotation class. This class represents a 3D cuboid annotation with position, rotation, and scale.

_type#

The type of annotation, set to AnnotationType.cuboid_3d.

Type:

AnnotationType

_points#

List of float values representing the position, rotation, and scale of the cuboid.

Type:

List[float]

label#

Optional label ID for the cuboid. Default is None.

Type:

Optional[int]

__init__()[source]#

Initializes the Cuboid3d with position, rotation, and scale.

position()#

Property to get and set the position of the cuboid.

rotation()#

Property to get and set the rotation of the cuboid.

scale()#

Property to get and set the scale of the cuboid.

Initialize the Cuboid3d with position, rotation, and scale.

Parameters:
  • position (List[float]) – List of 3 float values representing the position [x, y, z].

  • rotation (List[float], optional) – List of 3 float values representing the rotation [rx, ry, rz].

  • scale (List[float], optional) – List of 3 float values representing the scale [sx, sy, sz].

label: int | None#
property position#

Get the position of the cuboid.

Returns:

The position [x, y, z] of the cuboid.

Return type:

List[float]

property rotation#

Get the rotation of the cuboid.

Returns:

The rotation [rx, ry, rz] of the cuboid.

Return type:

List[float]

property scale#

Get the scale of the cuboid.

Returns:

The scale [sx, sy, sz] of the cuboid.

Return type:

List[float]

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

Bases: Shape

Polygon annotation class. This class represents a polygon shape defined by a series of points.

_type#

The type of annotation, set to AnnotationType.polygon.

Type:

AnnotationType

__attrs_post_init__()[source]#

Validates the points to ensure they form a valid polygon.

get_area()[source]#

Calculates the area of the polygon using the shoelace formula.

as_polygon()[source]#

Returns the points of the polygon.

__eq__()[source]#

Compares this polygon with another for equality.

_get_shoelace_area()[source]#

Helper method to calculate the area of the polygon using the shoelace formula.

Method generated by attrs for class Polygon.

get_area()[source]#

Calculate the area of the polygon using the shoelace formula.

Returns:

The area of the polygon.

Return type:

float

as_polygon() List[float][source]#

Return the points of the polygon.

Returns:

The points of the polygon.

Return type:

List[float]

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

Bases: Shape

Bbox annotation class. This class represents a bounding box defined by its top-left corner (x, y) and its width and height (w, h).

_type#

The type of annotation, set to AnnotationType.bbox.

Type:

AnnotationType

__init__()[source]#

Initializes the Bbox with its coordinates and dimensions.

x()#

Property to get the x-coordinate of the bounding box.

y()#

Property to get the y-coordinate of the bounding box.

w()#

Property to get the width of the bounding box.

h()#

Property to get the height of the bounding box.

get_area()[source]#

Calculates the area of the bounding box.

get_bbox()[source]#

Returns the bounding box coordinates and dimensions.

as_polygon()[source]#

Returns the bounding box as a list of points forming a polygon.

iou()[source]#

Calculates the Intersection over Union (IoU) with another shape.

wrap()[source]#

Creates a new Bbox instance with updated attributes.

Initialize the Bbox with its top-left corner (x, y) and its width and height (w, h).

Parameters:
  • x (float) – The x-coordinate of the top-left corner.

  • y (float) – The y-coordinate of the top-left corner.

  • w (float) – The width of the bounding box.

  • h (float) – The height of the bounding box.

property x#

Get the x-coordinate of the top-left corner of the bounding box.

Returns:

The x-coordinate of the bounding box.

Return type:

float

property y#

Get the y-coordinate of the top-left corner of the bounding box.

Returns:

The y-coordinate of the bounding box.

Return type:

float

property w#

Get the width of the bounding box.

Returns:

The width of the bounding box.

Return type:

float

property h#

Get the height of the bounding box.

Returns:

The height of the bounding box.

Return type:

float

get_area()[source]#

Calculate the area of the bounding box.

Returns:

The area of the bounding box.

Return type:

float

get_bbox()[source]#

Get the bounding box coordinates and dimensions.

Returns:

The bounding box as [x, y, w, h].

Return type:

List[float]

as_polygon() List[float][source]#

Convert the bounding box into a polygon representation.

Returns:

The bounding box as a polygon.

Return type:

List[float]

iou(other: Shape) float | ~typing.Literal[-1][source]#

Calculate the Intersection over Union (IoU) with another shape.

Parameters:

other (Shape) – The other shape to compare with.

Returns:

The IoU value or -1 if not applicable.

Return type:

Union[float, Literal[-1]]

wrap(**kwargs)[source]#

Create a new Bbox instance with updated attributes.

Parameters:
  • item (Bbox) – The original Bbox instance.

  • kwargs – Additional attributes to update.

Returns:

A new Bbox instance with updated attributes.

Return type:

Bbox

class datumaro.components.annotation.RotatedBbox(cx, cy, w, h, r, *args, **kwargs)[source]#

Bases: Shape

RotatedBbox annotation class. This class represents a rotated bounding box defined by its center (cx, cy), width (w), height (h), and rotation angle (r).

_type#

The type of annotation, set to AnnotationType.rotated_bbox.

Type:

AnnotationType

__init__()[source]#

Initializes the RotatedBbox with its center, dimensions, and rotation angle.

from_rectangle()[source]#

Creates a RotatedBbox from a list of four corner points.

cx()#

Property to get the x-coordinate of the center of the bounding box.

cy()#

Property to get the y-coordinate of the center of the bounding box.

w()#

Property to get the width of the bounding box.

h()#

Property to get the height of the bounding box.

r()#

Property to get the rotation angle of the bounding box.

get_area()[source]#

Calculates the area of the bounding box.

get_bbox()[source]#

Returns the bounding box coordinates and dimensions.

get_rotated_bbox()[source]#

Returns the rotated bounding box parameters.

as_polygon()[source]#

Converts the rotated bounding box into a list of corner points.

iou()[source]#

Calculates the Intersection over Union (IoU) with another shape.

wrap()[source]#

Creates a new RotatedBbox instance with updated attributes.

Initialize the RotatedBbox with its center (cx, cy), width (w), height (h), and rotation angle (r).

Parameters:
  • cx (float) – The x-coordinate of the center.

  • cy (float) – The y-coordinate of the center.

  • w (float) – The width of the bounding box.

  • h (float) – The height of the bounding box.

  • r (float) – The rotation angle of the bounding box in degrees.

classmethod from_rectangle(points: List[Tuple[float, float]], *args, **kwargs)[source]#

Create a RotatedBbox from a list of four corner points.

Parameters:
  • points (List[Tuple[float, float]]) – A list of four points defining the rectangle.

  • args – Additional arguments.

  • kwargs – Additional keyword arguments.

Returns:

A new RotatedBbox instance.

Return type:

RotatedBbox

property cx#

Get the x-coordinate of the center of the bounding box.

Returns:

The x-coordinate of the center.

Return type:

float

property cy#

Get the y-coordinate of the center of the bounding box.

Returns:

The y-coordinate of the center.

Return type:

float

property w#

Get the width of the bounding box.

Returns:

The width of the bounding box.

Return type:

float

property h#

Get the height of the bounding box.

Returns:

The height of the bounding box.

Return type:

float

property r#

Get the rotation angle of the bounding box in degrees.

Returns:

The rotation angle of the bounding box.

Return type:

float

get_area()[source]#

Calculate the area of the bounding box.

Returns:

The area of the bounding box.

Return type:

float

get_bbox()[source]#

Get the bounding box coordinates and dimensions.

Returns:

The bounding box as [x, y, w, h].

Return type:

List[float]

get_rotated_bbox()[source]#

Get the rotated bounding box parameters.

Returns:

The rotated bounding box as [cx, cy, w, h, r].

Return type:

List[float]

as_polygon() List[Tuple[float, float]][source]#

Convert the rotated bounding box into a list of corner points.

Returns:

The bounding box as a list of four corner points.

Return type:

List[Tuple[float, float]]

iou(other: Shape) float | ~typing.Literal[-1][source]#

Calculate the Intersection over Union (IoU) with another shape.

Parameters:

other (Shape) – The other shape to compare with.

Returns:

The IoU value or -1 if not applicable.

Return type:

Union[float, Literal[-1]]

wrap(**kwargs)[source]#

Create a new RotatedBbox instance with updated attributes.

Parameters:
  • item (RotatedBbox) – The original RotatedBbox instance.

  • kwargs – Additional attributes to update.

Returns:

A new RotatedBbox instance with updated attributes.

Return type:

RotatedBbox

class datumaro.components.annotation.Cuboid2D(_points: Iterable[Tuple[float, float]], *args, **kwargs)[source]#

Bases: Annotation

Cuboid2D annotation class. This class represents a 3D bounding box defined by its point coordinates in the following way: [(x1, y1), (x2, y2), (x3, y3), (x4, y4), (x5, y5), (x6, y6), (x7, y7), (x8, y8)].

2—3

/| /|

1-+-4 | | 5 + 6 |/ |/ 8—7

_type#

The type of annotation, set to AnnotationType.cuboid_2d.

Type:

AnnotationType

__init__()[source]#

Initializes the Cuboid2D with its coordinates.

wrap()#

Creates a new Cuboid2D instance with updated attributes.

Method generated by attrs for class Annotation.

points#
label: int | None#
z_order: int#
y_3d: float#
classmethod from_3d(dim: ndarray, location: ndarray, rotation_y: float, P: ndarray, Tr_velo_to_cam: ndarray) Cuboid2D[source]#

Creates an instance of Cuboid2D class from 3D bounding box parameters.

Parameters:
  • dim (np.ndarray) – 3 scalars describing length, width and height of a 3D bounding box

  • location (np.ndarray) – (x, y, z) coordinates of the middle of the top face.

  • rotation_y (np.ndarray) – rotation along the Y-axis (from -pi to pi)

  • P (np.ndarray) – Camera-to-Image transformation matrix (3x4)

  • Tr_velo_to_cam (np.ndarray) – LiDAR-to-Camera transformation matrix (3x4)

Returns:

Projection points for the given bounding box

Return type:

Cuboid2D

to_3d(P_inv: ndarray) tuple[ndarray, ndarray, float][source]#

Reconstructs 3D object Velodyne coordinates (dimensions, location and rotation along the Y-axis) from the given Cuboid2D instance.

Parameters:

P_inv (np.ndarray) – Pseudo-inverse of Camera-to-Image projection matrix

Returns:

dimensions, location and rotation along the Y-axis

Return type:

tuple

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

Bases: Categories

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

Method generated by attrs for class PointsCategories.

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

Bases: object

Method generated by attrs for class PointsCategories.Category.

labels: List[str]#
joints: Set[Tuple[int, int]]#
items: Dict[int, Category]#
classmethod from_iterable(iterable: Tuple[int, List[str]] | Tuple[int, List[str], Set[Tuple[int, int]]]) PointsCategories[source]#

Create PointsCategories from an iterable.

Parameters:

iterable

An Iterable with the following elements:

  • a label id

  • a list of positional arguments for Categories

Returns:

PointsCategories object

Return type:

PointsCategories

add(label_id: int, labels: Iterable[str] | None = None, joints: Iterable[Tuple[int, int]] | None = None)[source]#
class datumaro.components.annotation.Points(points, visibility: List[IntEnum] | None = None, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1, label=None, z_order: int = 0)[source]#

Bases: Shape

Represents an ordered set of points.

_type#

The type of annotation, set to AnnotationType.points.

Type:

AnnotationType

visibility#

A list indicating the visibility status of each point.

Type:

List[IntEnum]

Nested Class:
Visibility (IntEnum): Enum representing the visibility state of points. It has three states:
  • absent: Point is absent (0).

  • hidden: Point is hidden (1).

  • visible: Point is visible (2).

__attrs_post_init__()[source]#

Validates that the number of points is even.

get_area()[source]#

Returns the area covered by the points, always zero.

get_bbox()[source]#

Returns the bounding box containing all visible or hidden points.

Method generated by attrs for class Points.

class Visibility(value)[source]#

Bases: IntEnum

Enum representing the visibility state of points.

absent#

Point is absent (0).

Type:

int

hidden#

Point is hidden (1).

Type:

int

visible#

Point is visible (2).

Type:

int

absent = 0#
hidden = 1#
visible = 2#
visibility: List[IntEnum]#
get_area()[source]#

Returns the area covered by the points.

Returns:

Always returns 0.

Return type:

int

get_bbox()[source]#

Returns the bounding box containing all visible or hidden points.

Returns:

The bounding box as [x0, y0, width, height].

Return type:

List[float]

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

Bases: Annotation

Represents arbitrary text annotations.

Method generated by attrs for class Caption.

caption: str#
class datumaro.components.annotation.SuperResolutionAnnotation(image: Image, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#

Bases: _ImageAnnotation

Represents high resolution images.

Method generated by attrs for class SuperResolutionAnnotation.

class datumaro.components.annotation.DepthAnnotation(image: Image, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#

Bases: _ImageAnnotation

Represents depth images.

Method generated by attrs for class DepthAnnotation.

class datumaro.components.annotation.Ellipse(x1: float, y1: float, x2: float, y2: float, *args, **kwargs)[source]#

Bases: Shape

Ellipse represents an ellipse that is encapsulated by a rectangle.

  • x1 and y1 represent the top-left coordinate of the encapsulating rectangle

  • x2 and y2 representing the bottom-right coordinate of the encapsulating rectangle

Parameters:
  • x1 (float) – left x coordinate of encapsulating rectangle

  • y1 (float) – top y coordinate of encapsulating rectangle

  • x2 (float) – right x coordinate of encapsulating rectangle

  • y2 (float) – bottom y coordinate of encapsulating rectangle

Method generated by attrs for class Shape.

property x1#
property y1#
property x2#
property y2#
property w#
property h#
property c_x#
property c_y#
get_area()[source]#

Calculate the area of the shape.

get_bbox()[source]#

Calculate and return the bounding box of the shape.

Returns:

The bounding box as [x, y, w, h].

Return type:

Tuple[float, float, float, float]

get_points(num_points: int = 720) List[Tuple[float, float]][source]#

Return points as a list of tuples, e.g. [(x0, y0), (x1, y1), …].

Parameters:

num_points (int) – The number of boundary points of the ellipse. By default, one point is created for every 1 degree of interior angle (num_points=360).

as_polygon(num_points: int = 720) List[float][source]#

Return a polygon as a list of tuples, e.g. [x0, y0, x1, y1, …].

Parameters:

num_points (int) – The number of boundary points of the ellipse. By default, one point is created for every 1 degree of interior angle (num_points=360).

iou(other: Shape) float | ~typing.Literal[-1][source]#
wrap(**kwargs) Ellipse[source]#

Returns a modified copy of the object

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

Bases: Categories

Describes tabular data metainfo such as column names and types.

Method generated by attrs for class TabularCategories.

class Category(name, dtype: Type[TableDtype], labels: Set[str | int] = _Nothing.NOTHING)[source]#

Bases: object

Method generated by attrs for class TabularCategories.Category.

name: str#
dtype: Type[TableDtype]#
labels: Set[str | int]#
items: List[Category]#
classmethod from_iterable(iterable: Iterable[Tuple[str, Type[TableDtype]] | Tuple[str, Type[TableDtype], Set[str]]]) TabularCategories[source]#

Creates a TabularCategories from iterable.

Parameters:

iterable – a list of (Category name, type) or (Category name, type, set of labels)

Returns: a TabularCategories object

add(name: str, dtype: Type[TableDtype], labels: Set[str] | None = None) int[source]#

Add a Tabular Category.

Parameters:
  • name (str) – Column name

  • dtype (type) – Type of the corresponding column. (str, int, or float)

  • labels (optional, set(str)) – Label values where the column can have.

Returns:

A index of added category.

Return type:

int

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

Find Category information for the given column name.

Parameters:

name (str) – Column name

Returns:

A index and Category information.

Return type:

tuple(int, Category)

class datumaro.components.annotation.Tabular(values, *, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#

Bases: Annotation

Represents values of target columns in a tabular dataset.

Method generated by attrs for class Tabular.

values: Dict[str, TableDtype]#
class datumaro.components.annotation.Annotations(iterable=(), /)[source]#

Bases: List[Annotation]

List of Annotation equipped with additional utility functions.

get_semantic_seg_mask(ignore_index: int = 0, dtype: ~numpy.dtype = <class 'numpy.uint8'>) ndarray[source]#

Extract semantic segmentation mask from a collection of Datumaro `Mask`s.

Parameters:
  • ignore_index – Scalar value to fill in the zeros in each binary mask before merging into a semantic segmentation mask. This value is usually used to represent a pixel denoting a not-interested region. Defaults to 0.

  • dtype – Data type for the resulting mask. Defaults to np.uint8.

Returns:

Semantic segmentation mask generated by merging Datumaro `Mask`s.

Raises:

ValueError – If there are no mask annotations or if there is an inconsistency in mask sizes.