|
| 1 | +import logging |
1 | 2 | import sys |
2 | 3 | from functools import wraps |
3 | 4 | from typing import Dict, List, Tuple |
@@ -76,6 +77,40 @@ def _iou_assignments_for_same_reference_id( |
76 | 77 | polygon_annotations = list(map(polygon_annotation_to_shape, annotations)) |
77 | 78 | polygon_predictions = list(map(polygon_annotation_to_shape, predictions)) |
78 | 79 |
|
| 80 | + invalid_anns = [ |
| 81 | + ann |
| 82 | + for ann, poly in zip(annotations, polygon_annotations) |
| 83 | + if not poly.is_valid |
| 84 | + ] |
| 85 | + invalid_preds = [ |
| 86 | + pred |
| 87 | + for pred, poly in zip(predictions, polygon_predictions) |
| 88 | + if not poly.is_valid |
| 89 | + ] |
| 90 | + |
| 91 | + if invalid_anns or invalid_preds: |
| 92 | + # Filter out invalid polys |
| 93 | + polygon_annotations = [ |
| 94 | + poly |
| 95 | + for ann, poly in zip(annotations, polygon_annotations) |
| 96 | + if poly.is_valid |
| 97 | + ] |
| 98 | + polygon_predictions = [ |
| 99 | + poly |
| 100 | + for pred, poly in zip(predictions, polygon_predictions) |
| 101 | + if poly.is_valid |
| 102 | + ] |
| 103 | + invalid_dataset_ids = set( |
| 104 | + ann.reference_id for ann in invalid_anns |
| 105 | + ).union(set(pred.reference_id for pred in invalid_preds)) |
| 106 | + # TODO(gunnar): change to .id once field is surfaced) |
| 107 | + logging.warning( |
| 108 | + "Invalid polygons for dataset items: %s Annotations:%s, predictions: %s", |
| 109 | + invalid_dataset_ids, |
| 110 | + [a.annotation_id for a in invalid_anns], |
| 111 | + [p.annotation_id for p in invalid_preds], |
| 112 | + ) |
| 113 | + |
79 | 114 | # Compute IoU matrix and set IoU values below the threshold to 0. |
80 | 115 | iou_matrix = _iou_matrix(polygon_annotations, polygon_predictions) |
81 | 116 | iou_matrix[iou_matrix < iou_threshold] = 0 |
|
0 commit comments