# batch_transform

Python API: `luxonis_ml.data.augmentations.batch_transform`

## Classes

| Name | Description |
| --- | --- |
|
[`BatchTransform`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Base class for transforms that combine multiple samples. |

### class `BatchTransform`

```python
class BatchTransform(ABC, A.DualTransform)
```

Base class for transforms that combine multiple samples.

Attributes

| Name | Description |
| --- | --- |
| `batch_size` | Number of samples consumed by one application of the transform. |

Properties

| Name | Type | Description |
| --- | --- | --- |
|
[`targets`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| `dict[str, Callable]` | |

Methods

| Name | Description |
| --- | --- |
|
[`__init__`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Create a batch transformation. |
|
[`apply`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of images. |
|
[`apply_to_array`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of generic arrays. |
|
[`apply_to_bboxes`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of bounding boxes. |
|
[`apply_to_classification`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of classification labels. |
|
[`apply_to_instance_mask`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of instance segmentation masks. |
|
[`apply_to_keypoints`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of keypoints. |
|
[`apply_to_mask`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of semantic segmentation masks. |
|
[`apply_to_metadata`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Apply the transformation to a batch of metadata arrays. |
|
[`update_transform_params`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/augmentations/batch_transform.md)
| Update the parameters dictionary with the shape of the input images. |

#### property `targets`

```python
targets: dict[str, Callable]
```

#### method `__init__`

```python
def __init__(batch_size: int, **kwargs)
```

Create a batch transformation.

Batch transformations combine multiple images and their labels into one sample.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `batch_size` | `int` | Number of samples required by the augmentation. | required |
| `**kwargs` |  | Additional arguments passed to the parent Albumentations transform. |  |

#### method `apply`

```python
def apply(image_batch: list[np.ndarray], **kwargs) -> np.ndarray
```

Apply the transformation to a batch of images.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `image_batch` | `list[np.ndarray]` | Images to transform. Each image should be of shape (H, W, C) or (H, W). | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Single transformed image resulting from the combination of the input batch. |

#### method `apply_to_array`

```python
def apply_to_array(array_batch: list[np.ndarray], **kwargs) -> np.ndarray
```

Apply the transformation to a batch of generic arrays.

> **Note**
> The default implementation simply concatenates non-empty arrays. Override this method if a different behavior is desired.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `array_batch` | `list[np.ndarray]` | A batch of arrays to transform. | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` |  |

#### method `apply_to_bboxes`

```python
def apply_to_bboxes(bboxes_batch: list[np.ndarray], **kwargs) -> np.ndarray
```

Apply the transformation to a batch of bounding boxes.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bboxes_batch` | `list[np.ndarray]` | A batch of bounding boxes to transform. | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Transformed bounding boxes resulting from the combination of the input batch. |

#### method `apply_to_classification`

```python
def apply_to_classification(
    classification_batch: list[np.ndarray],
    **kwargs,
) -> np.ndarray
```

Apply the transformation to a batch of classification labels.

> **Note**
> The default implementation treats classification labels as binary and returns their logical OR. Override this method if a different behavior is desired.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `classification_batch` | `list[np.ndarray]` | A batch of classification labels to transform. | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` |  |

#### method `apply_to_instance_mask`

```python
def apply_to_instance_mask(masks_batch: list[np.ndarray], **kwargs) -> np.ndarray
```

Apply the transformation to a batch of instance segmentation masks.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `masks_batch` | `list[np.ndarray]` | Masks to transform. Each mask should be of shape (H, W, N), where N is the number of
instances. | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | A single instance masks of shape (Hout, Wout, N). |

#### method `apply_to_keypoints`

```python
def apply_to_keypoints(keypoints_batch: list[np.ndarray], **kwargs) -> np.ndarray
```

Apply the transformation to a batch of keypoints.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `keypoints_batch` | `list[np.ndarray]` | A batch of keypoints to transform. | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Transformed keypoints resulting from the combination of the input batch. |

#### method `apply_to_mask`

```python
def apply_to_mask(masks_batch: list[np.ndarray], **kwargs) -> np.ndarray
```

Apply the transformation to a batch of semantic segmentation masks.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `masks_batch` | `list[np.ndarray]` | Masks to transform. Each mask should be of shape (H, W, C) or (H, W). | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Single transformed mask resulting from the combination of the input batch. |

#### method `apply_to_metadata`

```python
def apply_to_metadata(metadata_batch: list[np.ndarray], **kwargs) -> np.ndarray
```

Apply the transformation to a batch of metadata arrays.

> **Note**
> The default implementation concatenates non-empty metadata arrays. Override this method if a different behavior is desired.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `metadata_batch` | `list[np.ndarray]` | A batch of metadata arrays to transform. | required |
| `**kwargs` |  | Additional implementation-specific arguments. |  |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` |  |

#### method `update_transform_params`

```python
def update_transform_params(
    params: dict[str, Any],
    data: dict[str, Any],
) -> dict[str, Any]
```

Update the parameters dictionary with the shape of the input images.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `params` | `dict[str, Any]` | Parameters to be updated | required |
| `data` | `dict[str, Any]` | Input data dictionary containing images/volumes | required |

Returns

| Type | Description |
| --- | --- |
| `dict[str, Any]` | Updated parameters dictionary with shape and transform-specific parameters. |
