Skip to content

Commit

Permalink
add check in transform for empty seg masks
Browse files Browse the repository at this point in the history
  • Loading branch information
tlpss committed Dec 16, 2024
1 parent b9d8182 commit ac4b75c
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ def apply_transform_to_coco_dataset( # type: ignore # noqa: C901
coco_dataset = CocoKeypointsDataset(**coco_dataset.model_dump(exclude_none=False))
transform_keypoints = all(annotation.keypoints is not None for annotation in coco_dataset.annotations)

except PydanticValidationError:
except PydanticValidationError as e:
print("not transforming keypoints due to pydantic validation error")
print(e)
transform_keypoints = False

# check if bboxes and masks are present
transform_bbox = all(annotation.bbox is not None for annotation in coco_dataset.annotations)
transform_segmentation = all(annotation.segmentation is not None for annotation in coco_dataset.annotations)

# check if seg masks are not empty arrays
for annotation in coco_dataset.annotations:
print(annotation.segmentation)
if isinstance(annotation.segmentation, list) and len(annotation.segmentation) == 0:
print("Empty segmentation mask found. Skipping segmentation transformation.")
transform_segmentation = False
break

print(f"Transforming keypoints = {transform_keypoints}")
print(f"Transforming bbox = {transform_bbox}")
print(f"Transforming segmentation = {transform_segmentation}")
Expand Down

0 comments on commit ac4b75c

Please sign in to comment.