(boxes1, boxes2)
| 42 | |
| 43 | # modified from torchvision to also return the union |
| 44 | def box_iou(boxes1, boxes2): |
| 45 | area1 = box_area(boxes1) |
| 46 | area2 = box_area(boxes2) |
| 47 | |
| 48 | lt = torch.max(boxes1[:, None, :2], boxes2[:, :2]) # [N,M,2] |
| 49 | rb = torch.min(boxes1[:, None, 2:], boxes2[:, 2:]) # [N,M,2] |
| 50 | |
| 51 | wh = (rb - lt).clamp(min=0) # [N,M,2] |
| 52 | inter = wh[:, :, 0] * wh[:, :, 1] # [N,M] |
| 53 | |
| 54 | union = area1[:, None] + area2 - inter |
| 55 | |
| 56 | iou = (inter+1e-6) / (union+1e-6) |
| 57 | return iou, union |
| 58 | |
| 59 | |
| 60 | def generalized_box_iou(boxes1, boxes2): |
no outgoing calls
no test coverage detected