Shortcuts

masks_to_boxes

torchvision.ops.masks_to_boxes(masks: Tensor) Tensor[source]

Compute the bounding boxes around the provided masks.

Returns a [N, 4] tensor containing bounding boxes. The boxes are in (x1, y1, x2, y2) format with 0 <= x1 < x2 and 0 <= y1 < y2.

Parameters:

masks (Tensor[N, H, W]) – masks to transform where N is the number of masks and (H, W) are the spatial dimensions.

Returns:

bounding boxes

Return type:

Tensor[N, 4]

Examples using masks_to_boxes:

Getting started with transforms v2

Getting started with transforms v2

Repurposing masks into bounding boxes

Repurposing masks into bounding boxes

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