@@ -101,8 +101,8 @@ def subclassification_miou(
101
101
miou across all subclasses.
102
102
"""
103
103
104
- subclass_predictions = _create_schema_lookup (subclass_predictions )
105
- subclass_labels = _create_schema_lookup (subclass_labels )
104
+ subclass_predictions = _create_name_lookup (subclass_predictions )
105
+ subclass_labels = _create_name_lookup (subclass_labels )
106
106
feature_schemas = set (subclass_predictions .keys ()).union (
107
107
set (subclass_labels .keys ()))
108
108
classification_iou = [
@@ -188,11 +188,7 @@ def feature_miou(predictions: List[Union[ObjectAnnotation,
188
188
f"Unexpected annotation found. Found { type (predictions [0 ])} " )
189
189
190
190
191
- def _create_schema_lookup (annotations : List [BaseAnnotation ]):
192
- grouped_annotations = defaultdict (list )
193
- for annotation in annotations :
194
- grouped_annotations [annotation .schema_id ] = annotation
195
- return grouped_annotations
191
+
196
192
197
193
198
194
def data_row_miou (ground_truth : Label ,
@@ -210,11 +206,9 @@ def data_row_miou(ground_truth: Label,
210
206
Returns:
211
207
float indicating the iou score for this data row.
212
208
"""
213
- annotation_types = None if include_classifications else Geometry
214
- prediction_annotations = predictions .get_annotations_by_attr (
215
- attr = "name" , annotation_types = annotation_types )
216
- ground_truth_annotations = ground_truth .get_annotations_by_attr (
217
- attr = "name" , annotation_types = annotation_types )
209
+
210
+ prediction_annotations = _create_name_lookup (predictions .annotations )
211
+ ground_truth_annotations = _create_name_lookup (ground_truth .annotations )
218
212
feature_schemas = set (prediction_annotations .keys ()).union (
219
213
set (ground_truth_annotations .keys ()))
220
214
ious = [
@@ -228,6 +222,11 @@ def data_row_miou(ground_truth: Label,
228
222
return None
229
223
return np .mean (ious )
230
224
225
+ def _create_name_lookup (annotations : List [BaseAnnotation ]):
226
+ grouped_annotations = defaultdict (list )
227
+ for annotation in annotations :
228
+ grouped_annotations [annotation .name ] = annotation
229
+ return grouped_annotations
231
230
232
231
def _get_vector_pairs (predictions : List [Geometry ],
233
232
ground_truths : List [Geometry ]):
@@ -249,15 +248,3 @@ def _polygon_iou(poly1: Polygon, poly2: Polygon) -> float:
249
248
def _mask_iou (mask1 : np .ndarray , mask2 : np .ndarray ) -> float :
250
249
"""Computes iou between two binary segmentation masks."""
251
250
return np .sum (mask1 & mask2 ) / np .sum (mask1 | mask2 )
252
-
253
-
254
- def _remove_opacity_channel (masks : List [np .ndarray ]) -> List [np .ndarray ]:
255
- return [mask [:, :, :3 ] if mask .shape [- 1 ] == 4 else mask for mask in masks ]
256
-
257
-
258
- def _instance_urls_to_binary_mask (urls : List [str ],
259
- color : Tuple [int , int , int ]) -> np .ndarray :
260
- """Downloads segmentation masks and turns the image into a binary mask."""
261
- masks = _remove_opacity_channel ([url_to_numpy (url ) for url in urls ])
262
- return np .sum ([np .all (mask == color , axis = - 1 ) for mask in masks ],
263
- axis = 0 ) > 0
0 commit comments