Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batch augmentations for p=0 #223

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions luxonis_ml/data/augmentations/batch_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def __call__(
for batch in yield_batches(data_batch, transform.batch_size):
data = transform(**batch) # type: ignore

if isinstance(next(iter(data.values())), list):
data = {key: value[0] for key, value in batch.items()}

data = self.check_data_post_transform(data)
new_batch.append(data)
data_batch = new_batch
Expand Down
9 changes: 6 additions & 3 deletions luxonis_ml/data/augmentations/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Iterator, List, Tuple
from typing import Dict, Iterator, List, Tuple, TypeVar

import numpy as np

Expand Down Expand Up @@ -66,9 +66,12 @@ def postprocess_keypoints(
return keypoints


T = TypeVar("T")


def yield_batches(
data_batch: List[Dict[str, Any]], batch_size: int
) -> Iterator[Dict[str, List[Any]]]:
data_batch: List[Dict[str, T]], batch_size: int
) -> Iterator[Dict[str, List[T]]]:
"""Yield batches of data.

@type data_batch: List[Dict[str, Any]]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_data/test_augmentations/test_batched.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@ def test_mixup(
config = [{"name": "MixUp", "params": {"p": 1.0}}]
augmentations = AlbumentationsEngine(256, 256, targets, config)
augmentations.apply([(image.copy(), deepcopy(labels)) for _ in range(2)])


def test_batched_p_0(
image: np.ndarray, labels: Labels, targets: Dict[str, TaskType]
):
config = [
{
"name": "Mosaic4",
"params": {"p": 0, "out_width": 640, "out_height": 640},
},
{"name": "MixUp", "params": {"p": 0}},
]
augmentations = AlbumentationsEngine(256, 256, targets, config)
augmentations.apply([(image.copy(), deepcopy(labels)) for _ in range(8)])
Loading