Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notes about BoundingBoxes transform utils in ops/boxes docstrings #8197

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions torchvision/ops/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def nms(boxes: Tensor, scores: Tensor, iou_threshold: float) -> Tensor:
to their intersection-over-union (IoU).

NMS iteratively removes lower scoring boxes which have an
IoU greater than iou_threshold with another (higher scoring)
IoU greater than :attr:`iou_threshold` with another (higher scoring)
bmmtstb marked this conversation as resolved.
Show resolved Hide resolved
box.

If multiple boxes have the exact same score and satisfy the IoU
Expand Down Expand Up @@ -114,7 +114,12 @@ def _batched_nms_vanilla(

def remove_small_boxes(boxes: Tensor, min_size: float) -> Tensor:
"""
Remove boxes which contains at least one side smaller than min_size.
Remove every box from :attr:`boxes` which contains at least one side length
that is smaller than :attr:`min_size`.
bmmtstb marked this conversation as resolved.
Show resolved Hide resolved

.. warning::
bmmtstb marked this conversation as resolved.
Show resolved Hide resolved
For sanitizing a :class:`~tv_tensors.BoundingBoxes` object, consider using
the transform :func:`~torchvision.transforms.v2.SanitizeBoundingBoxes` instead.
bmmtstb marked this conversation as resolved.
Show resolved Hide resolved

Args:
boxes (Tensor[N, 4]): boxes in ``(x1, y1, x2, y2)`` format
Expand All @@ -123,7 +128,7 @@ def remove_small_boxes(boxes: Tensor, min_size: float) -> Tensor:

Returns:
Tensor[K]: indices of the boxes that have both sides
larger than min_size
larger than :attr:`min_size`
bmmtstb marked this conversation as resolved.
Show resolved Hide resolved
"""
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
_log_api_usage_once(remove_small_boxes)
Expand All @@ -135,7 +140,11 @@ def remove_small_boxes(boxes: Tensor, min_size: float) -> Tensor:

def clip_boxes_to_image(boxes: Tensor, size: Tuple[int, int]) -> Tensor:
"""
Clip boxes so that they lie inside an image of size `size`.
Clip boxes so that they lie inside an image of size :attr:`size`.

.. warning::
For clipping a :class:`~tv_tensors.BoundingBoxes` object, consider using
the transform :func:`~torchvision.transforms.v2.ClampBoundingBoxes` instead.

Args:
boxes (Tensor[N, 4]): boxes in ``(x1, y1, x2, y2)`` format
Expand Down Expand Up @@ -167,15 +176,22 @@ def clip_boxes_to_image(boxes: Tensor, size: Tuple[int, int]) -> Tensor:

def box_convert(boxes: Tensor, in_fmt: str, out_fmt: str) -> Tensor:
"""
Converts boxes from given in_fmt to out_fmt.
Supported in_fmt and out_fmt are:
Converts :class:`torch.Tensor` boxes from a given :attr:`in_fmt` to :attr:`out_fmt`.

.. warning::
For converting a :class:`torch.Tensor` or a :class:`~tv_tensors.BoundingBoxes` object
between different :class:`~torchvision.tv_tensors.BoundingBoxFormat`s,
consider using :func:`~torchvision.transforms.v2.functional.convert_bounding_box_format` instead.
Or see the corresponding transform :func:`~torchvision.transforms.v2.ConvertBoundingBoxFormat`.

'xyxy': boxes are represented via corners, x1, y1 being top left and x2, y2 being bottom right.
Supported :attr:`in_fmt` and :attr:`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.
``'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
``'cxcywh'``: boxes are represented via centre, width and height, cx, cy being center of box, w, h
being width and height.

Args:
Expand Down Expand Up @@ -221,6 +237,10 @@ def box_area(boxes: Tensor) -> Tensor:
Computes the area of a set of bounding boxes, which are specified by their
(x1, y1, x2, y2) coordinates.

.. warning::
For computing the area of a :class:`~tv_tensors.BoundingBoxes` object
consider using :func:`~torchvision.transforms.v2.functional.get_size` instead.

bmmtstb marked this conversation as resolved.
Show resolved Hide resolved
Args:
boxes (Tensor[N, 4]): boxes for which the area will be computed. They
are expected to be in (x1, y1, x2, y2) format with
Expand Down
Loading