MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / box_iou

Function box_iou

SwissArmyTransformer/examples/yolos/util/box_ops.py:24–37  ·  view source on GitHub ↗
(boxes1, boxes2)

Source from the content-addressed store, hash-verified

22
23# modified from torchvision to also return the union
24def box_iou(boxes1, boxes2):
25 area1 = box_area(boxes1)
26 area2 = box_area(boxes2)
27
28 lt = torch.max(boxes1[:, None, :2], boxes2[:, :2]) # [N,M,2]
29 rb = torch.min(boxes1[:, None, 2:], boxes2[:, 2:]) # [N,M,2]
30
31 wh = (rb - lt).clamp(min=0) # [N,M,2]
32 inter = wh[:, :, 0] * wh[:, :, 1] # [N,M]
33
34 union = area1[:, None] + area2 - inter
35
36 iou = inter / union
37 return iou, union
38
39
40def generalized_box_iou(boxes1, boxes2):

Callers 1

generalized_box_iouFunction · 0.85

Calls 1

maxMethod · 0.45

Tested by

no test coverage detected