MCPcopy Create free account
hub / github.com/SooLab/CGFormer / box_iou

Function box_iou

utils/box_ops.py:44–57  ·  view source on GitHub ↗
(boxes1, boxes2)

Source from the content-addressed store, hash-verified

42
43# modified from torchvision to also return the union
44def box_iou(boxes1, boxes2):
45 area1 = box_area(boxes1)
46 area2 = box_area(boxes2)
47
48 lt = torch.max(boxes1[:, None, :2], boxes2[:, :2]) # [N,M,2]
49 rb = torch.min(boxes1[:, None, 2:], boxes2[:, 2:]) # [N,M,2]
50
51 wh = (rb - lt).clamp(min=0) # [N,M,2]
52 inter = wh[:, :, 0] * wh[:, :, 1] # [N,M]
53
54 union = area1[:, None] + area2 - inter
55
56 iou = (inter+1e-6) / (union+1e-6)
57 return iou, union
58
59
60def generalized_box_iou(boxes1, boxes2):

Callers 1

generalized_box_iouFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected