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(
254254
255255def _polygon_iou (poly1 : Polygon , poly2 : Polygon ) -> ScalarMetricValue :
256256 """Computes iou between two shapely polygons."""
257+ poly1 , poly2 = _ensure_valid_poly (poly1 ), _ensure_valid_poly (poly2 )
257258 if poly1 .intersects (poly2 ):
258259 return poly1 .intersection (poly2 ).area / poly1 .union (poly2 ).area
259260 return 0.
260261
261262
263+ def _ensure_valid_poly (poly ):
264+ if not poly .is_valid :
265+ return poly .buffer (0 )
266+ return poly
267+
268+
262269def _mask_iou (mask1 : np .ndarray , mask2 : np .ndarray ) -> ScalarMetricValue :
263270 """Computes iou between two binary segmentation masks."""
264271 return np .sum (mask1 & mask2 ) / np .sum (mask1 | mask2 )
You can’t perform that action at this time.
0 commit comments