From da9bb71aca4db9037be29e4d8bbf7b140c5fefc6 Mon Sep 17 00:00:00 2001 From: Burhan Qaddoumi Date: Tue, 3 Dec 2024 19:15:53 -0500 Subject: [PATCH] update union area in IOU calculation, use grits.iou in postprocess.py --- src/grits.py | 7 ++----- src/postprocess.py | 16 ++-------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/grits.py b/src/grits.py index c9d48280e..eba104c95 100644 --- a/src/grits.py +++ b/src/grits.py @@ -227,12 +227,9 @@ def iou(bbox1, bbox2): Compute the intersection-over-union of two bounding boxes. """ intersection = Rect(bbox1).intersect(bbox2) - union = Rect(bbox1).include_rect(bbox2) - - union_area = union.get_area() + union_area = Rect(bbox1).get_area() + Rect(bbox2).get_area() - intersection.get_area() if union_area > 0: - return intersection.get_area() / union.get_area() - + return intersection.get_area() / union_area return 0 diff --git a/src/postprocess.py b/src/postprocess.py index 25feaeede..3bfd68c0d 100644 --- a/src/postprocess.py +++ b/src/postprocess.py @@ -5,6 +5,8 @@ from fitz import Rect +from grits import iou + def apply_threshold(objects, threshold): """ @@ -31,20 +33,6 @@ def apply_class_thresholds(bboxes, labels, scores, class_names, class_thresholds return bboxes, scores, labels -def iou(bbox1, bbox2): - """ - Compute the intersection-over-union of two bounding boxes. - """ - intersection = Rect(bbox1).intersect(bbox2) - union = Rect(bbox1).include_rect(bbox2) - - union_area = union.get_area() - if union_area > 0: - return intersection.get_area() / union.get_area() - - return 0 - - def iob(bbox1, bbox2): """ Compute the intersection area over box area, for bbox1.