datumaro.plugins.data_formats.datumaro_binary.mapper#

class datumaro.plugins.data_formats.datumaro_binary.mapper.AnnotationListMapper[source]#

Bases: Mapper

backward_map = {AnnotationType.label: <bound method LabelMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.LabelMapper'>>, AnnotationType.mask: <bound method MaskMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.MaskMapper'>>, AnnotationType.points: <bound method PointsMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.PointsMapper'>>, AnnotationType.polygon: <bound method PolygonMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.PolygonMapper'>>, AnnotationType.polyline: <bound method PolyLineMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.PolyLineMapper'>>, AnnotationType.bbox: <bound method BboxMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.BboxMapper'>>, AnnotationType.caption: <bound method CaptionMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.CaptionMapper'>>, AnnotationType.cuboid_3d: <bound method Cuboid3dMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.Cuboid3dMapper'>>, AnnotationType.ellipse: <bound method EllipseMapper.backward of <class 'datumaro.plugins.data_formats.datumaro_binary.mapper.annotation.EllipseMapper'>>}#
classmethod forward(anns: List[Annotation]) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[List[Annotation], int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.LabelMapper[source]#

Bases: AnnotationMapper

ann_type = 1#
classmethod forward(ann: Label) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Label, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.MaskMapper[source]#

Bases: AnnotationMapper

ann_type = 2#
classmethod forward(ann: Mask) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Mask, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.RleMaskMapper[source]#

Bases: MaskMapper

Just clone MaskMapper.

class datumaro.plugins.data_formats.datumaro_binary.mapper.PointsMapper[source]#

Bases: _ShapeMapper

ann_type = 3#
classmethod forward(ann: Points) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Points, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.PolygonMapper[source]#

Bases: _ShapeMapper

ann_type = 4#
classmethod forward(ann: Polygon) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Polygon, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.PolyLineMapper[source]#

Bases: _ShapeMapper

ann_type = 5#
classmethod forward(ann: PolyLine) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[PolyLine, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.BboxMapper[source]#

Bases: _ShapeMapper

ann_type = 6#
classmethod forward(ann: Bbox) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Bbox, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.CaptionMapper[source]#

Bases: AnnotationMapper

ann_type = 7#
classmethod forward(ann: Caption) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Caption, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.Cuboid3dMapper[source]#

Bases: AnnotationMapper

ann_type = 8#
classmethod forward(ann: Cuboid3d) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Cuboid3d, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.EllipseMapper[source]#

Bases: _ShapeMapper

ann_type = 11#
classmethod forward(ann: Ellipse) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Ellipse, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.Mapper[source]#

Bases: ABC

abstract static forward(obj: Any) bytes[source]#

Convert an object to bytes.

abstract static backward(_bytes: bytes, offset: int = 0) Tuple[Any, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.DictMapper[source]#

Bases: Mapper

static forward(obj: Dict[str, Any]) bytes[source]#

Convert an object to bytes.

static backward(_bytes: bytes, offset: int = 0) Tuple[Dict[str, Any], int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.StringMapper[source]#

Bases: Mapper

static forward(obj: str) bytes[source]#

Convert an object to bytes.

static backward(_bytes: bytes, offset: int = 0) Tuple[str, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.IntListMapper[source]#

Bases: ListMapper

class datumaro.plugins.data_formats.datumaro_binary.mapper.FloatListMapper[source]#

Bases: ListMapper

class datumaro.plugins.data_formats.datumaro_binary.mapper.DatasetItemMapper[source]#

Bases: Mapper

static forward(obj: DatasetItem) bytes[source]#

Convert an object to bytes.

static backward(_bytes: bytes, offset: int = 0, media_path_prefix: Dict[MediaType, str] | None = None) Tuple[DatasetItem, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.MediaMapper[source]#

Bases: Mapper

classmethod forward(obj: MediaElement | None) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0, media_path_prefix: Dict[MediaType, str] | None = None) Tuple[MediaElement | None, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.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.plugins.data_formats.datumaro_binary.mapper.AnnotationMapper[source]#

Bases: Mapper

ann_type = 0#
classmethod forward(ann: Annotation) bytes[source]#

Convert an object to bytes.

classmethod backward_dict(_bytes: bytes, offset: int = 0) Tuple[Dict, int][source]#
classmethod backward(_bytes: bytes, offset: int = 0) Tuple[Annotation, int][source]#

Build an object from bytes.

static forward_optional_label(label: int | None) int[source]#
static backward_optional_label(label: int) int | None[source]#
static parse_ann_type(_bytes: bytes, offset: int = 0) AnnotationType[source]#
class datumaro.plugins.data_formats.datumaro_binary.mapper.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#
class datumaro.plugins.data_formats.datumaro_binary.mapper.Bbox(x, y, w, h, *args, **kwargs)[source]#

Bases: _Shape

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() List[float][source]#
iou(other: _Shape) float | ~typing.Literal[-1][source]#
wrap(**kwargs)[source]#

Returns a modified copy of the object

class datumaro.plugins.data_formats.datumaro_binary.mapper.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.plugins.data_formats.datumaro_binary.mapper.Cuboid3d(position, rotation=None, scale=None, **kwargs)[source]#

Bases: Annotation

Method generated by attrs for class Annotation.

label: int | None#
property position#

[x, y, z]

property rotation#

[rx, ry, rz]

property scale#

[sx, sy, sz]

class datumaro.plugins.data_formats.datumaro_binary.mapper.DatasetItem(id: str, *, subset: str | None = None, media: str | MediaElement | None = None, annotations: List[Annotation] | None = None, attributes: Dict[str, Any] | None = None)[source]#

Bases: object

id: str#
subset: str#
media: MediaElement | None#
annotations: List[Annotation]#
attributes: Dict[str, Any]#
wrap(**kwargs)[source]#
media_as(t: Type[T]) T[source]#
exception datumaro.plugins.data_formats.datumaro_binary.mapper.DatumaroError[source]#

Bases: Exception

class datumaro.plugins.data_formats.datumaro_binary.mapper.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]#
get_bbox()[source]#

Returns [x, y, w, h]

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.plugins.data_formats.datumaro_binary.mapper.Image(size: Tuple[int, int] | None = None, ext: str | None = None, *args, **kwargs)[source]#

Bases: MediaElement[ndarray]

classmethod from_file(path: str, *args, **kwargs)[source]#
classmethod from_numpy(data: ndarray | Callable[[], ndarray], *args, **kwargs)[source]#
classmethod from_bytes(data: bytes | Callable[[], bytes], *args, **kwargs)[source]#
property has_size: bool#

Indicates that size info is cached and won’t require image loading

property size: Tuple[int, int] | None#

Returns (H, W)

property ext: str | None#

Media file extension (with the leading dot)

set_crypter(crypter: Crypter)[source]#
class datumaro.plugins.data_formats.datumaro_binary.mapper.ImageMapper[source]#

Bases: MediaElementMapper

MAGIC_SIZE_FOR_NONE = (-1583, -1597)#
MEDIA_TYPE = 2#
classmethod forward(obj: Image) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0, media_path_prefix: Dict[MediaType, str] | None = None) Tuple[Image, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.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.plugins.data_formats.datumaro_binary.mapper.Mask(image, *, 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.plugins.data_formats.datumaro_binary.mapper.MediaElement(crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#

Bases: Generic[AnyData]

as_dict() Dict[str, Any][source]#
from_self(**kwargs)[source]#
property is_encrypted: bool#
set_crypter(crypter: Crypter)[source]#
property type: MediaType#
property data: AnyData | None#
property has_data: bool#
property bytes: bytes | None#
save(fp: str | ~io.IOBase, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
class datumaro.plugins.data_formats.datumaro_binary.mapper.MediaElementMapper[source]#

Bases: Mapper

MAGIC_PATH = '/NOT/A/REAL/PATH'#
MEDIA_TYPE = 1#
classmethod forward(obj: MediaElement) bytes[source]#

Convert an object to bytes.

classmethod backward_dict(_bytes: bytes, offset: int = 0, media_path_prefix: Dict[MediaType, str] | None = None) Tuple[Dict, int][source]#
classmethod backward(_bytes: bytes, offset: int = 0, media_path_prefix: Dict[MediaType, str] | None = None) Tuple[MediaElement, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.MediaType(value)[source]#

Bases: IntEnum

An enumeration.

NONE = 0#
MEDIA_ELEMENT = 1#
IMAGE = 2#
BYTE_IMAGE = 3#
VIDEO_FRAME = 4#
VIDEO = 5#
POINT_CLOUD = 6#
MULTIFRAME_IMAGE = 7#
ROI_IMAGE = 8#
MOSAIC_IMAGE = 9#
TABLE_ROW = 10#
property media: Type[MediaElement] | None#
class datumaro.plugins.data_formats.datumaro_binary.mapper.PointCloud(extra_images: List[Image] | Callable[[], List[Image]] | None = None, *args, **kwargs)[source]#

Bases: MediaElement[bytes]

classmethod from_file(path: str, *args, **kwargs)[source]#
classmethod from_bytes(data: bytes | Callable[[], bytes], *args, **kwargs)[source]#
property extra_images: List[Image]#
class datumaro.plugins.data_formats.datumaro_binary.mapper.PointCloudMapper[source]#

Bases: MediaElementMapper

MEDIA_TYPE = 6#
classmethod forward(obj: PointCloud) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0, media_path_prefix: Dict[MediaType, str] | None = None) Tuple[PointCloud, int][source]#

Build an object from bytes.

class datumaro.plugins.data_formats.datumaro_binary.mapper.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.

Method generated by attrs for class Points.

class Visibility(value)[source]#

Bases: IntEnum

An enumeration.

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

Returns [x, y, w, h]

class datumaro.plugins.data_formats.datumaro_binary.mapper.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

Method generated by attrs for class PolyLine.

as_polygon()[source]#
get_area()[source]#
class datumaro.plugins.data_formats.datumaro_binary.mapper.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

Method generated by attrs for class Polygon.

get_area()[source]#
as_polygon() List[float][source]#
class datumaro.plugins.data_formats.datumaro_binary.mapper.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.plugins.data_formats.datumaro_binary.mapper.Video(path: str, *, step: int = 1, start_frame: int = 0, end_frame: int | None = None)[source]#

Bases: MediaElement, Iterable[VideoFrame]

close()[source]#
get_frame_data(idx: int) VideoFrame[source]#
property length: int | None#

Returns frame count, if video provides such information.

Note that not all videos provide length / duration metainfo, so the result may be undefined.

Also note, that information may be inaccurate because of variable FPS in video or incorrect metainfo. The count is only guaranteed to be valid after video is completely read once.

The count is affected by the frame filtering options of the object, i.e. start frame, end frame and frame step.

property frame_size: Tuple[int, int]#

Returns (H, W)

save(fp: str | ~io.IOBase, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
property path: str#

Path to the media file

property ext: str#

Media file extension (with the leading dot)

class datumaro.plugins.data_formats.datumaro_binary.mapper.VideoFrame(video: Video, index: int)[source]#

Bases: ImageFromNumpy

as_dict() Dict[str, Any][source]#
property size: Tuple[int, int]#

Returns (H, W)

property index: int#
property video: Video#
property path: str#
class datumaro.plugins.data_formats.datumaro_binary.mapper.VideoFrameMapper[source]#

Bases: MediaElementMapper

MEDIA_TYPE = 4#
classmethod forward(obj: VideoFrame) bytes[source]#

Convert an object to bytes.

classmethod backward(_bytes: bytes, offset: int = 0, media_path_prefix: Dict[MediaType, str] | None = None) Tuple[VideoFrame, int][source]#

Build an object from bytes.

Modules

datumaro.plugins.data_formats.datumaro_binary.mapper.annotation

datumaro.plugins.data_formats.datumaro_binary.mapper.common

datumaro.plugins.data_formats.datumaro_binary.mapper.dataset_item

datumaro.plugins.data_formats.datumaro_binary.mapper.media