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
|
Apply an operation element-wise between a list column and a reference column. |
Classes
|
Convert bounding box coordinates between normalized and absolute formats. |
|
Lazy converter that loads images from file paths using Pillow. |
|
Converter that transforms RGB image format to BGR format. |
|
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
- 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
- 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]#
- 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