快捷方式

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, min_area: float = 1.0) Tuple[Tensor, Tensor][原始碼]

移除退化/無效的邊界框,並傳回相應的索引遮罩。

這會移除以下邊界框

  • 若邊界框的大小低於給定的 min_sizemin_area,則會被移除:預設情況下,這也會移除退化的邊界框,例如 X2 <= X1 的情況。

  • 若邊界框的任何座標超出其對應的圖片範圍,則會被移除。您可能需要先呼叫 clamp_bounding_boxes() 以避免不必要的移除。

建議在流程的最後,將輸入傳遞給模型之前呼叫此函式。如果呼叫了 RandomIoUCrop,則務必呼叫此轉換。如果您想更加謹慎,可以在所有可能修改邊界框的轉換之後呼叫它,但在大多數情況下,在最後呼叫一次就足夠了。

參數:
  • bounding_boxes (Tensor 或 BoundingBoxes) – 要清理的邊界框。

  • format (str 或 BoundingBoxFormat, optional) – 邊界框的格式。如果 bounding_boxes 是一個 BoundingBoxes 物件,則必須保留為 None。

  • canvas_size (tuple of python:int, optional) – 邊界框的 canvas_size(對應圖像/影片的大小)。如果 bounding_boxes 是一個 BoundingBoxes 物件,則必須保留為 None。

  • min_size (float, optional) –

  • min_area (float, optional) –

返回:

有效的邊界框子集,以及對應的索引遮罩。然後可以使用此遮罩來篩選與邊界框相關聯的其他 tensors(例如,標籤)。

返回類型:

out (tuple of Tensors)

文件

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