File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
labelbox/data/metrics/iou Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -254,11 +254,18 @@ def _get_mask_pairs(
254
254
255
255
def _polygon_iou (poly1 : Polygon , poly2 : Polygon ) -> ScalarMetricValue :
256
256
"""Computes iou between two shapely polygons."""
257
+ poly1 , poly2 = _ensure_valid_poly (poly1 ), _ensure_valid_poly (poly2 )
257
258
if poly1 .intersects (poly2 ):
258
259
return poly1 .intersection (poly2 ).area / poly1 .union (poly2 ).area
259
260
return 0.
260
261
261
262
263
+ def _ensure_valid_poly (poly ):
264
+ if not poly .is_valid :
265
+ return poly .buffer (0 )
266
+ return poly
267
+
268
+
262
269
def _mask_iou (mask1 : np .ndarray , mask2 : np .ndarray ) -> ScalarMetricValue :
263
270
"""Computes iou between two binary segmentation masks."""
264
271
return np .sum (mask1 & mask2 ) / np .sum (mask1 | mask2 )
You can’t perform that action at this time.
0 commit comments