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

Function box_iou

semantic_sam/utils/box_ops.py:29–42  ·  view source on GitHub ↗
(boxes1, boxes2)

Source from the content-addressed store, hash-verified

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

Callers 2

generalized_box_iouFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected