Given two lists of boxes of size N and M, compute the IoU (intersection over union) between **all** N x M pairs of boxes. The box order must be (xmin, ymin, xmax, ymax). Args: boxes1,boxes2 (Boxes): two `Boxes`. Contains N & M boxes, respectively. Returns: Tens
(boxes1: Boxes, boxes2: Boxes)
| 332 | # implementation from https://github.com/kuangliu/torchcv/blob/master/torchcv/utils/box.py |
| 333 | # with slight modifications |
| 334 | def pairwise_iou(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor: |
| 335 | """ |
| 336 | Given two lists of boxes of size N and M, compute the IoU |
| 337 | (intersection over union) between **all** N x M pairs of boxes. |
| 338 | The box order must be (xmin, ymin, xmax, ymax). |
| 339 | |
| 340 | Args: |
| 341 | boxes1,boxes2 (Boxes): two `Boxes`. Contains N & M boxes, respectively. |
| 342 | |
| 343 | Returns: |
| 344 | Tensor: IoU, sized [N,M]. |
| 345 | """ |
| 346 | area1 = boxes1.area() # [N] |
| 347 | area2 = boxes2.area() # [M] |
| 348 | inter = pairwise_intersection(boxes1, boxes2) |
| 349 | |
| 350 | # handle empty boxes |
| 351 | iou = torch.where( |
| 352 | inter > 0, |
| 353 | inter / (area1[:, None] + area2 - inter), |
| 354 | torch.zeros(1, dtype=inter.dtype, device=inter.device), |
| 355 | ) |
| 356 | return iou |
| 357 | |
| 358 | |
| 359 | def pairwise_ioa(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor: |
nothing calls this directly
no test coverage detected