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

Function pairwise_point_box_distance

PATH/core/models/ops/boxes.py:379–395  ·  view source on GitHub ↗

Pairwise distance between N points and M boxes. The distance between a point and a box is represented by the distance from the point to 4 edges of the box. Distances are all positive when the point is inside the box. Args: points: Nx2 coordinates. Each row is (x, y)

(points: torch.Tensor, boxes: Boxes)

Source from the content-addressed store, hash-verified

377
378
379def pairwise_point_box_distance(points: torch.Tensor, boxes: Boxes):
380 """
381 Pairwise distance between N points and M boxes. The distance between a
382 point and a box is represented by the distance from the point to 4 edges
383 of the box. Distances are all positive when the point is inside the box.
384
385 Args:
386 points: Nx2 coordinates. Each row is (x, y)
387 boxes: M boxes
388
389 Returns:
390 Tensor: distances of size (N, M, 4). The 4 values are distances from
391 the point to the left, top, right, bottom of the box.
392 """
393 x, y = points.unsqueeze(dim=2).unbind(dim=1) # (N, 1)
394 x0, y0, x1, y1 = boxes.tensor.unsqueeze(dim=0).unbind(dim=2) # (1, M)
395 return torch.stack([x - x0, y - y0, x1 - x, y1 - y], dim=2)
396
397
398def matched_pairwise_iou(boxes1: Boxes, boxes2: Boxes) -> torch.Tensor:

Callers

nothing calls this directly

Calls 1

stackMethod · 0.80

Tested by

no test coverage detected