Shortcuts

box_convert

torchvision.ops.box_convert(boxes: Tensor, in_fmt: str, out_fmt: str) Tensor[source]

Converts torch.Tensor boxes from a given in_fmt to out_fmt.

Note

For converting a torch.Tensor or a BoundingBoxes object between different formats, consider using convert_bounding_box_format() instead. Or see the corresponding transform ConvertBoundingBoxFormat().

Supported in_fmt and out_fmt strings are:

'xyxy': boxes are represented via corners, x1, y1 being top left and x2, y2 being bottom right. This is the format that torchvision utilities expect.

'xywh': boxes are represented via corner, width and height, x1, y2 being top left, w, h being width and height.

'cxcywh': boxes are represented via centre, width and height, cx, cy being center of box, w, h being width and height.

'xywhr': boxes are represented via corner, width and height, x1, y2 being top left, w, h being width and height. r is rotation angle w.r.t to the box center by |r| degrees counter clock wise in the image plan

'cxcywhr': boxes are represented via centre, width and height, cx, cy being center of box, w, h being width and height. r is rotation angle w.r.t to the box center by |r| degrees counter clock wise in the image plan

'xyxyxyxy': boxes are represented via corners, x1, y1 being top left, x2, y2 bottom right, x3, y3 bottom left, and x4, y4 top right.

Parameters:
  • boxes (Tensor[N, K]) – boxes which will be converted. K is the number of coordinates (4 for unrotated bounding boxes, 5 or 8 for rotated bounding boxes)

  • in_fmt (str) – Input format of given boxes. Supported formats are [‘xyxy’, ‘xywh’, ‘cxcywh’, ‘xywhr’, ‘cxcywhr’, ‘xyxyxyxy’].

  • out_fmt (str) – Output format of given boxes. Supported formats are [‘xyxy’, ‘xywh’, ‘cxcywh’, ‘xywhr’, ‘cxcywhr’, ‘xyxyxyxy’]

Returns:

Boxes into converted format.

Return type:

Tensor[N, K]

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