MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / pairwise_intersection

Function pairwise_intersection

PATH/core/models/ops/boxes.py:310–329  ·  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

308
309
310def pairwise_intersection(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor:
311 """
312 Given two lists of boxes of size N and M,
313 compute the intersection area between __all__ N x M pairs of boxes.
314 The box order must be (xmin, ymin, xmax, ymax)
315
316 Args:
317 boxes1,boxes2 (Boxes): two `Boxes`. Contains N & M boxes, respectively.
318
319 Returns:
320 Tensor: intersection, sized [N,M].
321 """
322 boxes1, boxes2 = boxes1.tensor, boxes2.tensor
323 width_height = torch.min(boxes1[:, None, 2:], boxes2[:, 2:]) - torch.max(
324 boxes1[:, None, :2], boxes2[:, :2]
325 ) # [N,M,2]
326
327 width_height.clamp_(min=0) # [N,M,2]
328 intersection = width_height.prod(dim=2) # [N,M]
329 return intersection
330
331
332# implementation from https://github.com/kuangliu/torchcv/blob/master/torchcv/utils/box.py

Callers 2

pairwise_iouFunction · 0.85
pairwise_ioaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected