From 65e9735bd9d73aa079f07e3973770749f1aae7f4 Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Mon, 9 Jan 2023 15:53:53 +0100 Subject: [PATCH] Refactor metrics --- cv_analysis/utils/test_metrics.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cv_analysis/utils/test_metrics.py b/cv_analysis/utils/test_metrics.py index f6d62c2..d8ada67 100644 --- a/cv_analysis/utils/test_metrics.py +++ b/cv_analysis/utils/test_metrics.py @@ -38,16 +38,13 @@ def rectangle_from_dict(d): def compute_page_iou(results_boxes: Iterable[Rectangle], ground_truth_boxes: Iterable[Rectangle]): results = list(results_boxes) truth = list(ground_truth_boxes) - if (not results) or (not truth): - return 0 - iou_sum = 0 - denominator = max(len(results), len(truth)) - while results and truth: - gt_box = truth.pop() + + def find_best_iou(gt_box): best_match, best_iou = find_max_overlap(gt_box, results) results.remove(best_match) - iou_sum += best_iou - score = iou_sum / denominator + return best_iou + + score = sum(map(find_best_iou, truth)) / max(len(results), len(truth)) return score