捷徑

RandomPerspective

class torchvision.transforms.RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=InterpolationMode.BILINEAR, fill=0)[source]

以給定的機率對給定的影像執行隨機透視轉換。如果影像是 torch Tensor,則預期具有 […, H, W] 形狀,其中 … 表示任意數量的 leading dimension。

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

  • p (float) – 影像被轉換的機率。預設值為 0.5。

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

  • fill (sequencenumber) – 用於轉換後影像外部區域的像素填充值。預設值為 0。如果給定一個數字,則該值分別用於所有波段。

使用 RandomPerspective 的範例

轉換的說明

轉換的說明
forward(img)[source]
參數:

img (PIL ImageTensor) – 要進行透視轉換的影像。

傳回:

隨機轉換後的影像。

傳回類型:

PIL Image 或 Tensor

static get_params(width: int, height: int, distortion_scale: float) Tuple[List[List[int]], List[List[int]]][source]

取得隨機透視變換的 perspective 參數。

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

  • height (int) – 影像的高度。

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

傳回:

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

文件

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