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

Function pairwise_intersection

detectron2/structures/boxes.py:322–341  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

320
321
322def 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

Callers 2

pairwise_iouFunction · 0.85
pairwise_ioaFunction · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected