Shortcuts

box_iou

torchvision.ops.box_iou(boxes1: Tensor, boxes2: Tensor, fmt: str = 'xyxy') Tensor[source]

Return intersection-over-union (Jaccard index) between two sets of boxes from a given format.

Parameters:
  • boxes1 (Tensor[..., N, K]) – first set of boxes

  • boxes2 (Tensor[..., M, K]) – second set of boxes

  • fmt (str) –

    Format of the input boxes. Default is “xyxy” to preserve backward compatibility.

    Supported axis-aligned formats (K=4):

    • 'xyxy': boxes are represented via (x1, y1, x2, y2) corner coordinates.

    • 'xywh': boxes are represented via (x1, y1, width, height).

    • 'cxcywh': boxes are represented via (cx, cy, width, height) center coordinates.

    Supported rotated formats:

    • 'cxcywhr' (K=5): boxes are represented via center, width, height, and rotation angle. (cx, cy) is the center, (w, h) is width and height, r is rotation angle in degrees (counter-clockwise positive).

    • 'xywhr' (K=5): boxes are represented via corner, width, height, and rotation angle. (x1, y1) is the top-left corner, (w, h) is width and height, r is rotation angle in degrees.

    • 'xyxyxyxy' (K=8): boxes are represented via 4 corner coordinates. (x1, y1) is top-left, (x2, y2) is top-right, (x3, y3) is bottom-right, (x4, y4) is bottom-left.

Returns:

the NxM matrix containing the pairwise IoU values for every element in boxes1 and boxes2

Return type:

Tensor[…, N, M]

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources