From d5626bbba9cda975901ef0f8ff6111f3c8de4755 Mon Sep 17 00:00:00 2001 From: timonpalm Date: Mon, 11 Nov 2024 23:17:14 +0100 Subject: [PATCH] empty segmentation fix --- sahi/postprocess/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sahi/postprocess/utils.py b/sahi/postprocess/utils.py index 193cb684..6fcae37c 100644 --- a/sahi/postprocess/utils.py +++ b/sahi/postprocess/utils.py @@ -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: