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

Function pairwise_iou

PATH/core/models/ops/boxes.py:334–356  ·  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: Tens

(boxes1: Boxes, boxes2: Boxes)

Source from the content-addressed store, hash-verified

332# implementation from https://github.com/kuangliu/torchcv/blob/master/torchcv/utils/box.py
333# with slight modifications
334def 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
359def pairwise_ioa(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor:

Callers

nothing calls this directly

Calls 2

pairwise_intersectionFunction · 0.85
areaMethod · 0.45

Tested by

no test coverage detected