快捷方式

RandomPerspective

class torchvision.transforms.v2.RandomPerspective(distortion_scale: float = 0.5, p: float = 0.5, interpolation: Union[InterpolationMode, int] = InterpolationMode.BILINEAR, fill: Union[int, float, Sequence[int], Sequence[float], None, dict[Union[type, str], Union[int, float, collections.abc.Sequence[int], collections.abc.Sequence[float], NoneType]] = 0)[原始碼]

以給定機率對輸入執行隨機透視變換。

如果輸入是 torch.TensorTVTensor(例如 ImageVideoBoundingBoxes 等),它可以具有任意數量的前置批處理維度。例如,影像可以具有 [..., C, H, W] 形狀。邊界框可以具有 [..., 4] 形狀。

引數:
  • distortion_scale (float, optional) – 控制失真程度的引數,範圍從 0 到 1。預設為 0.5。

  • p (float, optional) – 輸入被變換的機率。預設為 0.5。

  • interpolation (InterpolationMode, optional) – 由 torchvision.transforms.InterpolationMode 定義的所需插值列舉。預設為 InterpolationMode.BILINEAR。如果輸入是 Tensor,則僅支援 InterpolationMode.NEARESTInterpolationMode.BILINEAR。也接受相應的 Pillow 整數常量,例如 PIL.Image.BILINEAR

  • fill (number or tuple or dict, optional) – 當 padding_mode 為 constant 時使用的畫素填充值。預設為 0。如果為長度為 3 的元組,則分別用於填充 R、G、B 通道。填充值也可以是對映資料型別到填充值的字典,例如 fill={tv_tensors.Image: 127, tv_tensors.Mask: 0},其中 Image 將被填充為 127,Mask 將被填充為 0。

使用 RandomPerspective 的示例

關鍵點上的變換

關鍵點上的變換

轉換圖示

轉換圖示
static get_params(width: int, height: int, distortion_scale: float) tuple[list[list[int]], list[list[int]]][原始碼]

為隨機透視變換獲取 perspective 的引數。

引數:
  • width (int) – 影像寬度。

  • height (int) – 影像高度。

  • distortion_scale (float) – 控制失真程度的引數,範圍從 0 到 1。

返回:

包含 [左上角、右上角、右下角、左下角] 原始影像的列表,包含 [左上角、右上角、右下角、左下角] 變換後圖像的列表。

make_params(flat_inputs: list[Any]) dict[str, Any][原始碼]

用於覆蓋自定義變換的方法。

請參閱 如何編寫自己的 v2 變換

transform(inpt: Any, params: dict[str, Any]) Any[原始碼]

用於覆蓋自定義變換的方法。

請參閱 如何編寫自己的 v2 變換

文件

訪問全面的 PyTorch 開發者文件

檢視文件

教程

為初學者和高階開發者提供深入的教程

檢視教程

資源

查詢開發資源並讓您的問題得到解答

檢視資源