Given two lists of boxes of size N and M, compute the intersection area 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: Tensor: intersect
(boxes1: Boxes, boxes2: Boxes)
| 320 | |
| 321 | |
| 322 | def pairwise_intersection(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor: |
| 323 | """ |
| 324 | Given two lists of boxes of size N and M, |
| 325 | compute the intersection area between __all__ N x M pairs of boxes. |
| 326 | The box order must be (xmin, ymin, xmax, ymax) |
| 327 | |
| 328 | Args: |
| 329 | boxes1,boxes2 (Boxes): two `Boxes`. Contains N & M boxes, respectively. |
| 330 | |
| 331 | Returns: |
| 332 | Tensor: intersection, sized [N,M]. |
| 333 | """ |
| 334 | boxes1, boxes2 = boxes1.tensor, boxes2.tensor |
| 335 | width_height = torch.min(boxes1[:, None, 2:], boxes2[:, 2:]) - torch.max( |
| 336 | boxes1[:, None, :2], boxes2[:, :2] |
| 337 | ) # [N,M,2] |
| 338 | |
| 339 | width_height.clamp_(min=0) # [N,M,2] |
| 340 | intersection = width_height.prod(dim=2) # [N,M] |
| 341 | return intersection |
| 342 | |
| 343 | |
| 344 | # implementation from https://github.com/kuangliu/torchcv/blob/master/torchcv/utils/box.py |
no test coverage detected