Skip to content

Commit

Permalink
Give explicit error when ROI is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasteuwen committed Sep 25, 2023
1 parent 641f627 commit 5c322c4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dlup/data/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def convert_annotations(
boxes: dict[str, list[tuple[tuple[int, int], tuple[int, int]]]] = defaultdict(list)

roi_mask = np.zeros(region_size, dtype=np.int32)

has_roi = False
for curr_annotation in annotations:
holes_mask = None
if isinstance(curr_annotation, dlup.annotations.Point):
Expand All @@ -82,6 +82,7 @@ def convert_annotations(
[np.asarray(curr_annotation.exterior.coords).round().astype(np.int32)],
1,
)
has_roi = True
continue

if not (curr_annotation.label in index_map):
Expand All @@ -104,6 +105,10 @@ def convert_annotations(
# TODO: This is a bit hacky to ignore mypy here, but I don't know how to fix it.
mask = np.where(holes_mask == 1, original_values, mask) # type: ignore

# This is a hard to find bug, so better give an explicit error.
if not has_roi:
raise AnnotationError(f"ROI mask {roi_name} not found, please add a ROI mask to the annotations.")

return dict(points), dict(boxes), mask, roi_mask if roi_name else None


Expand Down

0 comments on commit 5c322c4

Please sign in to comment.