MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / pairwise_iou

Function pairwise_iou

detectron2/structures/boxes.py:346–368  ·  view source on GitHub ↗

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: T

(boxes1: Boxes, boxes2: Boxes)

Source from the content-addressed store, hash-verified

344# implementation from https://github.com/kuangliu/torchcv/blob/master/torchcv/utils/box.py
345# with slight modifications
346def pairwise_iou(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor:
347 """
348 Given two lists of boxes of size N and M,
349 compute the IoU (intersection over union)
350 between __all__ N x M pairs of boxes.
351 The box order must be (xmin, ymin, xmax, ymax).
352 Args:
353 boxes1,boxes2 (Boxes): two `Boxes`. Contains N & M boxes, respectively.
354
355 Returns:
356 Tensor: IoU, sized [N,M].
357 """
358 area1 = boxes1.area() # [N]
359 area2 = boxes2.area() # [M]
360 inter = pairwise_intersection(boxes1, boxes2)
361
362 # handle empty boxes
363 iou = torch.where(
364 inter > 0,
365 inter / (area1[:, None] + area2 - inter),
366 torch.zeros(1, dtype=inter.dtype, device=inter.device),
367 )
368 return iou
369
370
371def pairwise_ioa(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor:

Callers 6

label_anchorsMethod · 0.90
_evaluate_box_proposalsFunction · 0.90
_evaluate_box_proposalsFunction · 0.90
test_pairwise_iouMethod · 0.90

Calls 2

pairwise_intersectionFunction · 0.85
areaMethod · 0.45

Tested by 1

test_pairwise_iouMethod · 0.72