MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / generalized_box_iou

Function generalized_box_iou

PATH/core/models/ops/box_ops.py:52–73  ·  view source on GitHub ↗

Generalized IoU from https://giou.stanford.edu/ The boxes should be in [x0, y0, x1, y1] format Returns a [N, M] pairwise matrix, where N = len(boxes1) and M = len(boxes2)

(boxes1, boxes2)

Source from the content-addressed store, hash-verified

50
51
52def generalized_box_iou(boxes1, boxes2):
53 """
54 Generalized IoU from https://giou.stanford.edu/
55
56 The boxes should be in [x0, y0, x1, y1] format
57
58 Returns a [N, M] pairwise matrix, where N = len(boxes1)
59 and M = len(boxes2)
60 """
61 # degenerate boxes gives inf / nan results
62 # so do an early check
63 assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
64 assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
65 iou, union = box_iou(boxes1, boxes2)
66
67 lt = torch.min(boxes1[:, None, :2], boxes2[:, :2])
68 rb = torch.max(boxes1[:, None, 2:], boxes2[:, 2:])
69
70 wh = (rb - lt).clamp(min=0) # [N,M,2]
71 area = wh[:, :, 0] * wh[:, :, 1]
72
73 return iou - (area - union) / area
74
75
76def giou_iou(boxes1, boxes2):

Callers

nothing calls this directly

Calls 1

box_iouFunction · 0.85

Tested by

no test coverage detected