Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/trackers/eval/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,19 @@ def _calculate_box_ious(
boxes1 = np.asarray(boxes1, dtype=np.float64)
boxes2 = np.asarray(boxes2, dtype=np.float64)

# Calculate intersection coordinates
# boxes1: (N, 4), boxes2: (M, 4) -> broadcasting to (N, M, 4)
min_ = np.minimum(boxes1[:, np.newaxis, :], boxes2[np.newaxis, :, :])
max_ = np.maximum(boxes1[:, np.newaxis, :], boxes2[np.newaxis, :, :])

# Intersection: max of left edges to min of right edges
# min_[..., 2] is min of x1 values, max_[..., 0] is max of x0 values
intersection = np.maximum(min_[..., 2] - max_[..., 0], 0) * np.maximum(min_[..., 3] - max_[..., 1], 0)
# Calculate intersection dimensions by broadcasting each coordinate plane
# directly, without full (N, M, 4) arrays
intersection_width = np.maximum(
np.minimum(boxes1[:, np.newaxis, 2], boxes2[np.newaxis, :, 2])
- np.maximum(boxes1[:, np.newaxis, 0], boxes2[np.newaxis, :, 0]),
0,
)
intersection_height = np.maximum(
np.minimum(boxes1[:, np.newaxis, 3], boxes2[np.newaxis, :, 3])
- np.maximum(boxes1[:, np.newaxis, 1], boxes2[np.newaxis, :, 1]),
0,
)
intersection = intersection_width * intersection_height

# Area of boxes1
area1 = (boxes1[..., 2] - boxes1[..., 0]) * (boxes1[..., 3] - boxes1[..., 1])
Expand Down
Loading