快捷方式

RandomPerspective

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

以給定機率對給定影像執行隨機透視變換。如果影像是 torch Tensor,則期望其形狀為 […, H, W],其中 … 表示任意數量的前導維度。

引數:
  • 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。

返回:

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

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源