Skip to content

Commit 11a6bfe

Browse files
committed
make bbox_area_threshold configurable
1 parent 59c90bc commit 11a6bfe

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

luxonis_ml/data/augmentations/albumentations_engine.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,13 @@ def __init__(
282282
is_validation_pipeline: bool = False,
283283
min_bbox_visibility: float = 0.0,
284284
seed: int | None = None,
285+
bbox_area_threshold: float = 0.0004,
285286
):
286287
self.targets: dict[str, TargetType] = {}
287288
self.target_names_to_tasks = {}
288289
self.n_classes = n_classes
289290
self.image_size = (height, width)
291+
self.bbox_area_threshold = bbox_area_threshold
290292

291293
for task, task_type in targets.items():
292294
target_name = self.task_to_target_name(task)
@@ -572,7 +574,9 @@ def postprocess(
572574
task_name = get_task_name(task)
573575

574576
if target_type == "bboxes":
575-
out_labels[task], index = postprocess_bboxes(array)
577+
out_labels[task], index = postprocess_bboxes(
578+
array, self.bbox_area_threshold
579+
)
576580
bboxes_indices[task_name] = index
577581

578582
for target_name, target_type in self.targets.items():

luxonis_ml/data/augmentations/base_engine.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
is_validation_pipeline: bool,
3131
min_bbox_visibility: float = 0.0,
3232
seed: int | None = None,
33+
bbox_area_threshold: float = 0.0004,
3334
):
3435
"""Initialize augmentation pipeline from configuration.
3536
@@ -67,6 +68,9 @@ def __init__(
6768
pipeline (in which case some augmentations are skipped)
6869
@type min_bbox_visibility: float
6970
@param min_bbox_visibility: Minimum fraction of the original bounding box that must remain visible after augmentation.
71+
@type bbox_area_threshold: float
72+
@param bbox_area_threshold: Minimum area threshold for bounding boxes to be considered valid. In the range [0, 1].
73+
Default is 0.0004, which corresponds to a small area threshold to remove invalid bboxes and respective keypoints.
7074
@type seed: Optional[int]
7175
@param seed: Random seed for reproducibility. If None, a random seed will be used.
7276
If provided, it will be used to initialize the random number generator.

luxonis_ml/data/augmentations/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def postprocess_mask(mask: np.ndarray) -> np.ndarray:
3939
return mask.transpose(2, 0, 1)
4040

4141

42-
def postprocess_bboxes(bboxes: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
43-
area_threshold = 0.0004 # 0.02 * 0.02 Small area threshold to remove invalid bboxes and respective keypoints.
42+
def postprocess_bboxes(
43+
bboxes: np.ndarray, area_threshold: float = 0.0004
44+
) -> tuple[np.ndarray, np.ndarray]:
4445
if bboxes.size == 0:
4546
return np.zeros((0, 5)), np.zeros((0,), dtype=np.uint8)
4647
ordering = bboxes[:, -1]

0 commit comments

Comments
 (0)