@@ -222,16 +222,15 @@ def _compute_average_precision(recall: np.ndarray, precision: np.ndarray) -> flo
222
222
Returns:
223
223
(float): Average precision.
224
224
"""
225
- extended_recall = np .concatenate (([0.0 ], recall , [1.0 ]))
226
- extended_precision = np .concatenate (([1.0 ], precision , [0.0 ]))
227
- max_accumulated_precision = np .flip (
228
- np .maximum .accumulate (np .flip (extended_precision ))
229
- )
230
- interpolated_recall_levels = np .linspace (0 , 1 , 101 )
231
- interpolated_precision = np .interp (
232
- interpolated_recall_levels , extended_recall , max_accumulated_precision
233
- )
234
- average_precision = np .trapz (interpolated_precision , interpolated_recall_levels )
225
+ if len (recall ) == 0 and len (precision ) == 0 :
226
+ return 0.0
227
+
228
+ recall_levels = np .linspace (0 , 1 , 101 )
229
+ precision_levels = np .zeros_like (recall_levels )
230
+ for r , p in zip (recall [::- 1 ], precision [::- 1 ]):
231
+ precision_levels [recall_levels <= r ] = p
232
+
233
+ average_precision = (1 / 100 * precision_levels ).sum ()
235
234
return average_precision
236
235
237
236
@staticmethod
@@ -307,9 +306,9 @@ def _average_precisions_per_class(
307
306
308
307
false_positives = (1 - matches [is_class ]).cumsum (0 )
309
308
true_positives = matches [is_class ].cumsum (0 )
310
- true_negatives = total_true - true_positives
309
+ false_negatives = total_true - true_positives
311
310
312
- recall = true_positives / (true_positives + true_negatives + eps )
311
+ recall = true_positives / (true_positives + false_negatives + eps )
313
312
precision = true_positives / (true_positives + false_positives )
314
313
315
314
for iou_level_idx in range (matches .shape [1 ]):
0 commit comments