Shortcuts

sanitize_bounding_boxes

torchvision.transforms.v2.functional.sanitize_bounding_boxes(bounding_boxes: Tensor, format: Optional[BoundingBoxFormat] = None, canvas_size: Optional[Tuple[int, int]] = None, min_size: float = 1.0) Tuple[Tensor, Tensor][source]

Remove degenerate/invalid bounding boxes and return the corresponding indexing mask.

This removes bounding boxes that:

  • are below a given min_size: by default this also removes degenerate boxes that have e.g. X2 <= X1.

  • have any coordinate outside of their corresponding image. You may want to call clamp_bounding_boxes() first to avoid undesired removals.

It is recommended to call it at the end of a pipeline, before passing the input to the models. It is critical to call this transform if RandomIoUCrop was called. If you want to be extra careful, you may call it after all transforms that may modify bounding boxes but once at the end should be enough in most cases.

Parameters:
  • bounding_boxes (Tensor or BoundingBoxes) – The bounding boxes to be sanitized.

  • format (str or BoundingBoxFormat, optional) – The format of the bounding boxes. Must be left to none if bounding_boxes is a BoundingBoxes object.

  • canvas_size (tuple of python:int, optional) – The canvas_size of the bounding boxes (size of the corresponding image/video). Must be left to none if bounding_boxes is a BoundingBoxes object.

  • min_size (float, optional) –

Returns:

The subset of valid bounding boxes, and the corresponding indexing mask. The mask can then be used to subset other tensors (e.g. labels) that are associated with the bounding boxes.

Return type:

out (tuple of Tensors)

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