(boxes1, boxes2)
| 27 | |
| 28 | # modified from torchvision to also return the union |
| 29 | def 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 | |
| 45 | def generalized_box_iou(boxes1, boxes2): |
no outgoing calls
no test coverage detected