Skip to content

Commit

Permalink
Attempt to fix SegFault
Browse files Browse the repository at this point in the history
  • Loading branch information
LinasKo committed May 17, 2024
1 parent b3b7455 commit ab775d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion supervision/dataset/formats/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def _mask_has_multiple_segments(mask: np.ndarray) -> bool:
if mask.size == 0:
return False
mask_uint8 = mask.astype(np.uint8)
number_of_labels, _ = cv2.connectedComponents(mask_uint8, connectivity=4)
labels = np.zeros_like(mask_uint8, dtype=np.int32)
number_of_labels, _ = cv2.connectedComponents(mask_uint8, labels, connectivity=4)
return number_of_labels > 2


Expand Down
4 changes: 2 additions & 2 deletions test/dataset/formats/test_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def test_build_coco_class_index_mapping(
# area=5 * 5,
# segmentation=[[0, 0, 2, 0, 2, 2, 4, 2, 4, 4, 0, 4]])],
# DoesNotRaise(),
# ), # segmentation mask in single component,no holes in mask, expects polygon mask
# ), # seg mask in single component,no holes in mask, expects polygon
(
Detections(
xyxy=np.array([[0, 0, 5, 5]], dtype=np.float32),
Expand Down Expand Up @@ -564,7 +564,7 @@ def test_build_coco_class_index_mapping(
)
],
DoesNotRaise(),
), # segmentation mask in single component, with holes in mask, expects RLE mask
), # seg mask in single component, with holes in mask, expects RLE mask
],
)
def test_detections_to_coco_annotations(
Expand Down

0 comments on commit ab775d9

Please sign in to comment.