MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / generalized_box_iou_padded

Function generalized_box_iou_padded

semantic_sam/utils/box_ops.py:68–89  ·  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

66 return iou - (area - union) / (area+1e-6)
67
68def generalized_box_iou_padded(boxes1, boxes2):
69 """
70 Generalized IoU from https://giou.stanford.edu/
71
72 The boxes should be in [x0, y0, x1, y1] format
73
74 Returns a [N, M] pairwise matrix, where N = len(boxes1)
75 and M = len(boxes2)
76 """
77 # degenerate boxes gives inf / nan results
78 # so do an early check
79 # assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
80 # assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
81 iou, union = box_iou(boxes1, boxes2)
82
83 lt = torch.min(boxes1[:, None, :2], boxes2[:, :2])
84 rb = torch.max(boxes1[:, None, 2:], boxes2[:, 2:])
85
86 wh = (rb - lt).clamp(min=0) # [N,M,2]
87 area = wh[:, :, 0] * wh[:, :, 1]
88
89 return iou - (area - union) / (area+1e-6)
90
91
92def masks_to_boxes(masks):

Callers

nothing calls this directly

Calls 1

box_iouFunction · 0.85

Tested by

no test coverage detected