fix val with half

This commit is contained in:
wa22 2024-05-30 15:46:06 +08:00
parent cf32e2f7f0
commit 8f0984817d

View File

@ -64,6 +64,9 @@ def box_iou(box1, box2, eps=1e-7):
(torch.Tensor): An NxM tensor containing the pairwise IoU values for every element in box1 and box2.
"""
# NOTE: need float32 to get accurate iou values
box1 = torch.as_tensor(box1, dtype=torch.float32)
box2 = torch.as_tensor(box2, dtype=torch.float32)
# inter(N,M) = (rb(N,M,2) - lt(N,M,2)).clamp(0).prod(2)
(a1, a2), (b1, b2) = box1.unsqueeze(1).chunk(2, 2), box2.unsqueeze(0).chunk(2, 2)
inter = (torch.min(a2, b2) - torch.max(a1, b1)).clamp_(0).prod(2)