(boxes1, boxes2)
| 22 | |
| 23 | # modified from torchvision to also return the union |
| 24 | def box_iou(boxes1, boxes2): |
| 25 | area1 = box_area(boxes1) |
| 26 | area2 = box_area(boxes2) |
| 27 | |
| 28 | lt = torch.max(boxes1[:, None, :2], boxes2[:, :2]) # [N,M,2] |
| 29 | rb = torch.min(boxes1[:, None, 2:], boxes2[:, 2:]) # [N,M,2] |
| 30 | |
| 31 | wh = (rb - lt).clamp(min=0) # [N,M,2] |
| 32 | inter = wh[:, :, 0] * wh[:, :, 1] # [N,M] |
| 33 | |
| 34 | union = area1[:, None] + area2 - inter |
| 35 | |
| 36 | iou = inter / union |
| 37 | return iou, union |
| 38 | |
| 39 | |
| 40 | def generalized_box_iou(boxes1, boxes2): |
no test coverage detected