datumaro.components.media#

Classes

FromDataMixin(data, *args, **kwargs)

FromFileMixin(path, *args, **kwargs)

Image([size, ext])

ImageFromBytes(data, *args, **kwargs)

ImageFromData(data, *args, **kwargs)

ImageFromFile(path, *args, **kwargs)

ImageFromNumpy(data, *args, **kwargs)

MediaElement(crypter, *args, **kwargs)

MediaType(value)

An enumeration.

MosaicImage(*args, **kwargs)

MosaicImageFromData(data, *args, **kwargs)

MosaicImageFromImageRoIPairs(data, size)

MultiframeImage(images, *[, path])

PointCloud([extra_images])

PointCloudFromBytes(data, *args, **kwargs)

PointCloudFromData(data, *args, **kwargs)

PointCloudFromFile(path, *args, **kwargs)

RoIImage(roi, *args, **kwargs)

RoIImageFromBytes(data, roi, *args, **kwargs)

RoIImageFromData(data, *args, **kwargs)

RoIImageFromFile(path, roi, *args, **kwargs)

RoIImageFromNumpy(data, roi, *args, **kwargs)

Table()

Table data with multiple rows and columns.

TableFromCSV(path[, dtype, sep, encoding])

Read a '.csv' file and compose a Table instance.

TableFromDataFrame(data, *args, **kwargs)

Read a pandas DataFrame and compose a Table instance.

TableFromListOfDict(data, *args, **kwargs)

Read a list of table row data and compose a Table instance.

TableRow(table, index)

TableRow media refers to a Table instance and its row index.

Video(path[, step, start_frame, end_frame])

VideoFrame(video, index)

class datumaro.components.media.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.components.media.MediaElement(crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>, *args, **kwargs)[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.components.media.FromFileMixin(path: str, *args, **kwargs)[source]#

Bases: object

property path: str#

Path to the media file

property bytes: bytes | None#
property has_data: bool#
class datumaro.components.media.FromDataMixin(data: Callable[[], AnyData] | AnyData, *args, **kwargs)[source]#

Bases: Generic[AnyData]

property data: AnyData | None#
property bytes: bytes | None#
property has_data: bool#
class datumaro.components.media.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.components.media.ImageFromFile(path: str, *args, **kwargs)[source]#

Bases: FromFileMixin, Image

property data: ndarray | None#

Image data in BGRA HWC [0; 255] (uint8) format

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

Returns (H, W)

save(fp: str | ~io.IOBase, ext: str | None = None, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
set_crypter(crypter: Crypter)[source]#
class datumaro.components.media.ImageFromData(data: Callable[[], AnyData] | AnyData, *args, **kwargs)[source]#

Bases: FromDataMixin, Image

save(fp: str | ~io.IOBase, ext: str | None = None, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
class datumaro.components.media.ImageFromNumpy(data: Callable[[], bytes] | bytes, *args, **kwargs)[source]#

Bases: ImageFromData

property data: ndarray | None#

Image data in BGRA HWC [0; 255] (uint8) format

property has_size: bool#

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

class datumaro.components.media.ImageFromBytes(data: Callable[[], bytes] | bytes, *args, **kwargs)[source]#

Bases: ImageFromData

property data: ndarray | None#

Image data in BGRA HWC [0; 255] (uint8) format

class datumaro.components.media.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#
from_self(**kwargs)[source]#
class datumaro.components.media.Video(path: str, step: int = 1, start_frame: int = 0, end_frame: int | None = None, *args, **kwargs)[source]#

Bases: MediaElement, Iterable[VideoFrame]

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

Returns frame count of the closed interval [start_frame, end_frame], 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.components.media.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.components.media.PointCloudFromFile(path: str, *args, **kwargs)[source]#

Bases: FromFileMixin, PointCloud

property data: bytes | None#
save(fp: str | ~io.IOBase, extra_images_fn: ~typing.Callable[[int, ~datumaro.components.media.Image], ~typing.Dict[str, ~typing.Any]] | None = None, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
class datumaro.components.media.PointCloudFromData(data: Callable[[], AnyData] | AnyData, *args, **kwargs)[source]#

Bases: FromDataMixin, PointCloud

save(fp: str | ~io.IOBase, extra_images_fn: ~typing.Callable[[int, ~datumaro.components.media.Image], ~typing.Dict[str, ~typing.Any]] | None = None, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
class datumaro.components.media.PointCloudFromBytes(data: Callable[[], AnyData] | AnyData, *args, **kwargs)[source]#

Bases: PointCloudFromData

property data: bytes | None#
class datumaro.components.media.MultiframeImage(images: Iterable[str | Image | ndarray | Callable[[str], ndarray]] | None, *, path: str | None = None)[source]#

Bases: MediaElement

property data: List[Image]#
property path: str#

Path to the media file

property ext: str#

Media file extension (with the leading dot)

class datumaro.components.media.RoIImage(roi: Tuple[int, int, int, int], *args, **kwargs)[source]#

Bases: Image

as_dict() Dict[str, Any][source]#
classmethod from_file(*args, **kwargs)[source]#
classmethod from_image(data: Image, roi: Tuple[int, int, int, int], *args, **kwargs)[source]#
classmethod from_numpy(*args, **kwargs)[source]#
classmethod from_bytes(*args, **kwargs)[source]#
property roi: Tuple[int, int, int, int]#
save(fp: str | ~io.IOBase, ext: str | None = None, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
class datumaro.components.media.RoIImageFromFile(path: str, roi: Tuple[int, int, int, int], *args, **kwargs)[source]#

Bases: FromFileMixin, RoIImage

property data: ndarray | None#

Image data in BGRA HWC [0; 255] (uint8) format

class datumaro.components.media.RoIImageFromData(data: Callable[[], AnyData] | AnyData, *args, **kwargs)[source]#

Bases: FromDataMixin, RoIImage

class datumaro.components.media.RoIImageFromBytes(data: bytes | Callable[[], bytes], roi: Tuple[int, int, int, int], *args, **kwargs)[source]#

Bases: RoIImageFromData

property data: ndarray | None#

Image data in BGRA HWC [0; 255] (uint8) format

class datumaro.components.media.RoIImageFromNumpy(data: ndarray | Callable[[], ndarray], roi: Tuple[int, int, int, int], *args, **kwargs)[source]#

Bases: RoIImageFromData

property data: ndarray | None#

Image data in BGRA HWC [0; 255] (uint8) format

class datumaro.components.media.MosaicImage(*args, **kwargs)[source]#

Bases: Image

classmethod from_file(*args, **kwargs)[source]#
classmethod from_image_roi_pairs(data: List[Tuple[Image, Tuple[int, int, int, int]]], size: Tuple[int, int], *args, **kwargs)[source]#
classmethod from_numpy(*args, **kwargs)[source]#
classmethod from_bytes(*args, **kwargs)[source]#
class datumaro.components.media.MosaicImageFromData(data: Callable[[], AnyData] | AnyData, *args, **kwargs)[source]#

Bases: FromDataMixin, MosaicImage

save(fp: str | ~io.IOBase, ext: str | None = None, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#
class datumaro.components.media.MosaicImageFromImageRoIPairs(data: List[Tuple[Image, Tuple[int, int, int, int]]], size: Tuple[int, int])[source]#

Bases: MosaicImageFromData

as_dict() Dict[str, Any][source]#
class datumaro.components.media.Table[source]#

Bases: object

Table data with multiple rows and columns. This provides random access to the table row.

Initialization must be done in the child class.

classmethod from_csv(path: str, *args, **kwargs) Type[Table][source]#

Returns Table instance creating from a csv file.

Parameters:

path (str) – Path to csv file.

classmethod from_dataframe(data: DataFrame | Callable[[], DataFrame], *args, **kwargs) Type[Table][source]#

Returns Table instance creating from a pandas DataFrame.

Parameters:

data (DataFrame) – Data in pandas DataFrame format.

classmethod from_list(data: List[Dict[str, TableDtype]], *args, **kwargs) Type[Table][source]#

Returns Table instance creating from a list of dicts.

Parameters:

data (list(dict(str,str|int|float))) – A list of table row data.

property shape: Tuple[int, int]#

Returns table size as (#rows, #cols)

property columns: List[str]#

Returns column names

dtype(column: str) Type[TableDtype] | None[source]#

Returns native python type for a given column

features(column: str, unique: bool | None = False) List[TableDtype][source]#

Get features for a given column name.

save(path: str)[source]#

Save table instance to a ‘.csv’ file.

Parameters:

path (str) – Path to the output csv file.

class datumaro.components.media.TableFromCSV(path: str, dtype: Dict | None = None, sep: str | None = None, encoding: str | None = None, *args, **kwargs)[source]#

Bases: FromFileMixin, Table

Read a ‘.csv’ file and compose a Table instance.

Parameters:
  • path (str) – Path to csv file.

  • dtype (optional, dict(str,str)) – Dictionay of column name -> type str (‘str’, ‘int’, or ‘float’).

  • sep (optional, str) – Delimiter to use.

  • encoding (optional, str) – Encoding to use for UTF when reading/writing (ex. ‘utf-8’).

property data: DataFrame | None#

Table data in pandas DataFrame format

select(columns: List[str])[source]#
class datumaro.components.media.TableFromDataFrame(data: Callable[[], DataFrame] | DataFrame, *args, **kwargs)[source]#

Bases: FromDataMixin, Table

Read a pandas DataFrame and compose a Table instance.

Parameters:

data (DataFrame) – Data in pandas DataFrame format.

property data: DataFrame | None#

Table data in pandas DataFrame format

class datumaro.components.media.TableFromListOfDict(data: List[Dict[str, TableDtype]], *args, **kwargs)[source]#

Bases: TableFromDataFrame

Read a list of table row data and compose a Table instance. The table row data is in dictionary format.

Parameters:

data (list(dict(str,str|int|float))) – A list of table row data.

class datumaro.components.media.TableRow(table: Table, index: int)[source]#

Bases: MediaElement

TableRow media refers to a Table instance and its row index.

Parameters:
  • table (Table) – Table instance.

  • index (int) – Row index.

property table: Table#

Table instance

property index: int#

Row index

data(targets: List[str] | None = None) Dict[source]#

Row data in dict format.

Parameters:

targets (optional, list(str)) – If this is specified, the values corresponding to target colums will be returned. Otherwise, whole row data will be returned.