Skip to content

Commit

Permalink
empty segmentation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timonpalm committed Nov 11, 2024
1 parent 3c8f593 commit d5626bb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sahi/postprocess/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ def get_merged_mask(pred1: ObjectPrediction, pred2: ObjectPrediction) -> Mask:
# buffer(0) is a quickhack to fix invalid polygons most of the time
poly1 = get_shapely_multipolygon(mask1.segmentation).buffer(0)
poly2 = get_shapely_multipolygon(mask2.segmentation).buffer(0)
union_poly = poly1.union(poly2)

if poly1.is_empty:
union_poly = poly2
elif poly2.is_empty:
union_poly = poly1
else:
union_poly = poly1.union(poly2)

if not hasattr(union_poly, "geoms"):
union_poly = MultiPolygon([union_poly])
else:
Expand Down

0 comments on commit d5626bb

Please sign in to comment.