# luxonis_loader

Python API: `luxonis_ml.data.loaders.luxonis_loader`

## Classes

| Name | Description |
| --- | --- |
|
[`LuxonisLoader`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/loaders/luxonis_loader.md)
| Indexed loader for
[LuxonisDataset](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/luxonis_dataset.md)
samples. |

### class `LuxonisLoader`

```python
class LuxonisLoader(BaseLoader)
```

Indexed loader for
[LuxonisDataset](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/luxonis_dataset.md)
samples.

[LuxonisLoader](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/loaders/luxonis_loader.md)
reads one split or multiple splits, loads image sources, assembles labels by task key, optionally applies augmentations, and
returns
[LoaderOutput](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
values with images, labels, and sample metadata.

Iterating a
[LoaderOutput](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
preserves the legacy tuple behavior: for a single-source dataset it yields `(image, labels)`. For a multi-source dataset it yields
`(images, labels)`, where `images` maps source names to arrays.

Prefer attribute access for new code:

```python
sample = loader[0]

images = sample.images
labels = sample.labels
metadata = sample.metadata
```

`sample.metadata` contains record-level metadata from
[DatasetRecord.sample_metadata](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/ldf/annotation.md).
When `autopopulate_metadata` is enabled, the loader also adds a `"filenames"` mapping from source name to file basename. Augmented
outputs additionally include an `"augmentations"` mapping from configured transformation paths to the runtime parameters that were
selected. Both are reserved keys that never overwrite metadata stored on the record.

Label keys use `"task_name/task_type"`. If a dataset was created without a task name, the default task name is empty and keys look
like `"/boundingbox"` or `"/segmentation"`.

Attributes

| Name | Description |
| --- | --- |
| `augmentations` | Optional augmentation engine. Its applied configured paths are added to augmented output metadata. |
| `autopopulate_metadata` | Whether automatic metadata such as source filenames is added to
[LoaderOutput.metadata](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md).
|
| `classes` | Class-name mappings per task. |
| `color_space` | Output color space per source. |
| `dataset` | Dataset being loaded. |
| `df` | Dataframe with records used by the loader. |
| `exclude_empty_annotations` | Whether empty annotations are omitted. |
| `filter_task_names` | Optional task-name allowlist. |
| `height` | Optional output image height. |
| `idx_to_df_row` | Mapping from loader index to dataframe row indices. |
| `instances` | Group IDs included in the selected views. |
| `keep_categorical_as_strings` | Whether categorical metadata remains as strings. |
| `source_names` | Source names expected in each sample. |
| `sync_mode` | Whether the dataset is remote and pulled before loading. |
| `tasks_without_background` | Segmentation tasks where unassigned pixels are mapped to background class 0. |
| `view` | Split names loaded by this loader. |
| `width` | Optional output image width. |

Methods

| Name | Description |
| --- | --- |
|
[`__init__`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/loaders/luxonis_loader.md)
| Create a loader for a Luxonis dataset. |

#### method `__init__`

```python
def __init__(
    dataset: LuxonisDataset,
    view: str | list[str] = 'train',
    augmentation_engine: Literal['albumentations'] | str = 'albumentations',
    augmentation_config: list[Params] | PathType | None = None,
    height: int | None = None,
    width: int | None = None,
    keep_aspect_ratio: bool = True,
    exclude_empty_annotations: bool = False,
    color_space: dict[str, Literal['RGB', 'BGR', 'GRAY']] | Literal['RGB', 'BGR', 'GRAY'] | None = None,
    seed: int | None = None,
    min_bbox_visibility: float = 0.0,
    bbox_area_threshold: float = 0.0004,
    *,
    keep_categorical_as_strings: bool = False,
    update_mode: UpdateMode | Literal['all', 'missing'] = UpdateMode.ALL,
    filter_task_names: list[str] | None = None,
    autopopulate_metadata: bool = True,
)
```

Create a loader for a Luxonis dataset.

> **Example**
> ```python
augmentation_config = [
    {
        "name": "Defocus",
        "params": {"p": 1},
    },
    {
        "name": "RandomCrop",
        "params": {"height": 512, "width": 512, "p": 1},
    },
    {
        "name": "Mosaic4",
        "params": {
            "height": 256,
            "width": 256,
            "p": 1.0,
        },
    },
]

loader = LuxonisLoader(
    dataset,
    view="train",
    augmentation_config=augmentation_config,
    height=640,
    width=640,
)
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `dataset` | `LuxonisDataset` | Dataset to load from. | required |
| `view` | `str | list[str]` | Split name or split names to load. | `'train'` |
| `augmentation_engine` | `Literal['albumentations'] | str` | Augmentation engine registry name. | `'albumentations'` |
| `augmentation_config` | `list[Params] | PathType | None` | Optional augmentation configuration or path to a configuration file. Each configuration item contains `name` and optional `params` keys. | `None` |
| `height` | `int | None` | Optional output image height. Required when augmentations are enabled. | `None` |
| `width` | `int | None` | Optional output image width. Required when augmentations are enabled. | `None` |
| `keep_aspect_ratio` | `bool` | Whether resizing should preserve image aspect ratio. | `True` |
| `exclude_empty_annotations` | `bool` | Whether to omit empty annotations from the returned label dictionary. | `False` |
| `color_space` | `dict[str, Literal['RGB', 'BGR', 'GRAY']] | Literal['RGB', 'BGR', 'GRAY'] | None` | Optional color space for each source. A single value applies to all sources; if omitted, all sources use `"RGB"`. | `None` |
| `seed` | `int | None` | Optional random seed for augmentations. | `None` |
| `min_bbox_visibility` | `float` | Minimum fraction of the original bounding box that must remain visible after augmentation. | `0.0` |
| `bbox_area_threshold` | `float` | Minimum normalized area for bounding boxes to remain valid. The default removes very small boxes and their associated keypoints. | `0.0004` |
| `keep_categorical_as_strings` | `bool` | Whether to keep categorical metadata labels as strings instead of converting them to integers. | `False` |
| `update_mode` | `UpdateMode | Literal['all', 'missing']` | Sync mode for media files in remote datasets. Annotations and metadata are always overwritten. | `UpdateMode.ALL` |
| `filter_task_names` | `list[str] | None` | Optional task names to include. If omitted, all tasks are included. | `None` |
| `autopopulate_metadata` | `bool` | Whether to add automatic sample metadata such as source filenames. When enabled, returned metadata includes a `"filenames"` dictionary keyed by source name. Set to `False` to return only metadata stored in [DatasetRecord.sample_metadata](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/ldf/annotation.md). Augmentation provenance is reported either way, as it describes the returned arrays rather than the record. | `True` |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If [color_space](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/loaders/luxonis_loader.md) is neither a string nor a dictionary. |
| `ValueError` | If [filter_task_names](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/loaders/luxonis_loader.md) contains task names not present in the dataset. |
| `RuntimeError` | If split metadata is missing. |
