Skip to content

Commit

Permalink
Documentação e remoção de restrição de classes iguais
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrevmatias committed Nov 27, 2020
1 parent e594f90 commit 978d947
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lapixdl/evaluation/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def evaluate_detection(gt_bboxes: Iterable[List[BBox]],
def calculate_pairwise_bbox_ious(gt_bboxes: List[BBox],
pred_bboxes: List[BBox]) -> List[List[float]]:
"""Calculates the [gt x pred] matrix of pairwise IoUs of GT and predicted bboxes of an image.
Bboxes of distinct classes have IoU = 0.
Args:
gt_bboxes (List[BBox]): GT bboxes
Expand Down Expand Up @@ -153,23 +152,25 @@ def calculate_bbox_iou(bbox_a: BBox, bbox_b: BBox) -> float:
Returns:
float: IoU between the two bboxes.
"""
if bbox_a.cls != bbox_b.cls:
return 0.0


# Gets each box upper left and bottom right coordinates
(upr_lft_x_a, upr_lft_y_a) = bbox_a.upper_left_point
(btm_rgt_x_a, btm_rgt_y_a) = bbox_a.bottom_right_point

(upr_lft_x_b, upr_lft_y_b) = bbox_b.upper_left_point
(btm_rgt_x_b, btm_rgt_y_b) = bbox_b.bottom_right_point

# Calculates the intersection box upper left and bottom right coordinates
(upr_lft_x_intersect, upr_lft_y_intersect) = (
max(upr_lft_x_a, upr_lft_x_b), max(upr_lft_y_a, upr_lft_y_b))
(btm_rgt_x_intersect, btm_rgt_y_intersect) = (
min(btm_rgt_x_a, btm_rgt_x_b), min(btm_rgt_y_a, btm_rgt_y_b))

# Calculates the height and width of the intersection box
(w_intersect, h_intersect) = (btm_rgt_x_intersect -
upr_lft_x_intersect + 1, btm_rgt_y_intersect - upr_lft_y_intersect + 1)

# IoU = 0 if there is no intersection
if (w_intersect <= 0) or (h_intersect <= 0):
return 0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_calculate_pairwise_bbox_ious():
]
pred_bboxes = [
BBox(54, 66, 198-54+1, 114-66+1, 0),
BBox(42, 78, 186-42+1, 126-78+1, 1),
BBox(42, 78, 186-42+1, 126-78+1, 0),
BBox(18, 63, 235-18+1, 135-63+1, 0),
BBox(54, 72, 198-54+1, 120-72+1, 0),
BBox(36, 60, 180-36+1, 108-60+1, 0),
Expand All @@ -27,9 +27,8 @@ def test_calculate_pairwise_bbox_ious():

ious = calculate_pairwise_bbox_ious(gt_bboxes, pred_bboxes)

assert ious[1, 1] == 0

assert round(ious[0, 0], 3) == .798
assert round(ious[1, 1], 3) == .79
assert round(ious[2, 2], 3) == .612
assert round(ious[3, 3], 3) == .947
assert round(ious[4, 4], 3) == .731
Expand Down

0 comments on commit 978d947

Please sign in to comment.