datumaro.experimental.converters#

Converter implementations for data transformation between different schemas.

This module contains concrete converter implementations that handle various data transformations such as format conversions, dtype conversions, and multi-field transformations.

Functions

list_eval_ref(list_col, ref_col, op)

Apply an operation element-wise between a list column and a reference column.

Classes

BBoxCoordinateConverter(**kwargs)

Convert bounding box coordinates between normalized and absolute formats.

ImagePathToImageConverter(**kwargs)

Lazy converter that loads images from file paths using Pillow.

RGBToBGRConverter(**kwargs)

Converter that transforms RGB image format to BGR format.

UInt8ToFloat32Converter(**kwargs)

Convert image data from UInt8 to Float32 with normalization.

class datumaro.experimental.converters.RGBToBGRConverter(**kwargs: Any)[source]#

Bases: Converter

Converter that transforms RGB image format to BGR format.

This converter swaps the red and blue channels of RGB images to produce BGR format images, commonly used for OpenCV compatibility.

Initialize converter with input and output AttributeSpec instances.

Parameters:

**kwargs – AttributeSpec instances for converter inputs/outputs based on input_*/output_* class attributes

input_image: AttributeSpec[ImageField]#
output_image: AttributeSpec[ImageField]#
filter_output_spec() bool[source]#

Check if input is RGB and configure output for BGR conversion.

Returns:

True if the converter should be applied (RGB to BGR), False otherwise

convert(df: DataFrame) DataFrame[source]#

Convert RGB image format to BGR using numpy channel swapping.

Parameters:

df – Input DataFrame containing RGB image data

Returns:

DataFrame with BGR image data in the output column

lazy: bool = False#

Whether this converter performs lazy operations.

Lazy converters defer expensive operations (like loading images from disk) until data is actually accessed. When a lazy converter is in the conversion path, all dependent converters must also be executed lazily.

class datumaro.experimental.converters.UInt8ToFloat32Converter(**kwargs: Any)[source]#

Bases: Converter

Convert image data from UInt8 to Float32 with normalization.

This converter transforms 8-bit integer pixel values (0-255) to 32-bit floating point values normalized to the range [0.0, 1.0].

Initialize converter with input and output AttributeSpec instances.

Parameters:

**kwargs – AttributeSpec instances for converter inputs/outputs based on input_*/output_* class attributes

input_image: AttributeSpec[ImageField]#
output_image: AttributeSpec[ImageField]#
filter_output_spec() bool[source]#

Check if input uses UInt8 dtype and configure Float32 output.

Returns:

True if the converter should be applied (UInt8 input), False otherwise

convert(df: DataFrame) DataFrame[source]#

Convert image data from UInt8 to normalized Float32.

Transforms pixel values from the range [0, 255] to [0.0, 1.0] by dividing by 255.0.

Parameters:

df – Input DataFrame containing UInt8 image data

Returns:

DataFrame with normalized Float32 image data

lazy: bool = False#

Whether this converter performs lazy operations.

Lazy converters defer expensive operations (like loading images from disk) until data is actually accessed. When a lazy converter is in the conversion path, all dependent converters must also be executed lazily.

class datumaro.experimental.converters.ImagePathToImageConverter(**kwargs: Any)[source]#

Bases: Converter

Lazy converter that loads images from file paths using Pillow.

This converter reads image files from disk and converts them to tensor format. It’s marked as lazy to defer the expensive I/O operation until the data is actually accessed.

Initialize converter with input and output AttributeSpec instances.

Parameters:

**kwargs – AttributeSpec instances for converter inputs/outputs based on input_*/output_* class attributes

input_path: AttributeSpec[ImagePathField]#
output_image: AttributeSpec[ImageField]#
filter_output_spec() bool[source]#

Configure output image specification based on input.

convert(df: DataFrame) DataFrame[source]#

Convert image paths to loaded image tensors.

Parameters:

df – DataFrame containing image path column

Returns:

DataFrame with loaded image data and shape information

lazy: bool = True#

Whether this converter performs lazy operations.

Lazy converters defer expensive operations (like loading images from disk) until data is actually accessed. When a lazy converter is in the conversion path, all dependent converters must also be executed lazily.

datumaro.experimental.converters.list_eval_ref(list_col: str, ref_col: str, op: Callable[[Expr, Expr], Expr]) Expr[source]#

Apply an operation element-wise between a list column and a reference column.

This helper function enables operations between elements of a list column and values from a reference column, returning a new list column with the results.

Parameters:
  • list_col – Name of the list column

  • ref_col – Name of the reference column

  • op – Operation function to apply between list elements and reference values

Returns:

Polars expression for the computed list column

Note

See pola-rs/polars#7210 for implementation details

class datumaro.experimental.converters.BBoxCoordinateConverter(**kwargs: Any)[source]#

Bases: Converter

Convert bounding box coordinates between normalized and absolute formats.

This converter handles transformations between normalized coordinates (range [0,1]) and absolute pixel coordinates using image dimensions.

Initialize converter with input and output AttributeSpec instances.

Parameters:

**kwargs – AttributeSpec instances for converter inputs/outputs based on input_*/output_* class attributes

input_bbox: AttributeSpec[BBoxField]#
input_image: AttributeSpec[ImageField]#
output_bbox: AttributeSpec[BBoxField]#
filter_output_spec() bool[source]#

Check if bbox normalization conversion is needed and configure output.

Returns:

True if conversion is needed (normalization status differs), False otherwise

convert(df: DataFrame) DataFrame[source]#

Convert bbox coordinates between normalized and absolute formats.

Uses image dimensions to transform coordinates. For normalized to absolute: multiplies by image dimensions. For absolute to normalized: divides by image dimensions.

Parameters:

df – Input DataFrame containing bbox and image data

Returns:

DataFrame with converted bounding box coordinates

lazy: bool = False#

Whether this converter performs lazy operations.

Lazy converters defer expensive operations (like loading images from disk) until data is actually accessed. When a lazy converter is in the conversion path, all dependent converters must also be executed lazily.