Skip to content

Commit 2a1cec4

Browse files
bowenc0221facebook-github-bot
authored andcommitted
support using bitmask with LSJ
Summary: `polygons_to_bitmask` fails with empty polygon which could happen with LSJ. Pull Request resolved: fairinternal/detectron2#564 Reviewed By: HannaMao Differential Revision: D31181422 Pulled By: ppwwyyxx fbshipit-source-id: 5f955e04518bae153401df0760840f5daf0da66a
1 parent be945b3 commit 2a1cec4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

detectron2/structures/masks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def polygons_to_bitmask(polygons: List[np.ndarray], height: int, width: int) ->
2828
Returns:
2929
ndarray: a bool mask of shape (height, width)
3030
"""
31-
assert len(polygons) > 0, "COCOAPI does not support empty polygons"
31+
if len(polygons) == 0:
32+
# COCOAPI does not support empty polygons
33+
return np.zeros((height, width)).astype(np.bool)
3234
rles = mask_util.frPyObjects(polygons, height, width)
3335
rle = mask_util.merge(rles)
3436
return mask_util.decode(rle).astype(np.bool)

0 commit comments

Comments
 (0)