快捷方式

RandomAffine

class torchvision.transforms.RandomAffine(degrees, translate=None, scale=None, shear=None, interpolation=InterpolationMode.NEAREST, fill=0, center=None)[源]

對影像進行隨機仿射變換,保持中心不變。如果影像是 torch Tensor,則其形狀應為 […, H, W],其中 … 表示任意數量的前導維度。

引數:
  • degrees (序列或數字) – 選擇角度的範圍。如果 degrees 是一個數字而不是像 (min, max) 這樣的序列,則角度範圍將是 (-degrees, +degrees)。設定為 0 可取消旋轉。

  • translate (元組, 可選) – 水平和垂直平移的最大絕對分陣列成的元組。例如 translate=(a, b),則水平偏移量將在 -img_width * a < dx < img_width * a 範圍內隨機取樣,垂直偏移量將在 -img_height * b < dy < img_height * b 範圍內隨機取樣。預設不進行平移。

  • scale (元組, 可選) – 縮放因子區間,例如 (a, b),則縮放因子將在 a <= scale <= b 範圍內隨機取樣。預設保持原始比例。

  • shear (序列或數字, 可選) – 選擇角度的範圍。如果 shear 是一個數字,則將應用平行於 x 軸、範圍為 (-shear, +shear) 的剪下。如果 shear 是包含 2 個值的序列,則將應用平行於 x 軸、範圍為 (shear[0], shear[1]) 的剪下。如果 shear 是包含 4 個值的序列,則將應用 x 軸剪下 (shear[0], shear[1]) 和 y 軸剪下 (shear[2], shear[3])。預設不應用剪下。

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

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

  • center (序列, 可選) – 可選的旋轉中心,(x, y)。原點是左上角。預設是影像中心。

使用 RandomAffine 的示例

變換示例

變換示例
forward(img)[源]

img (PIL Image 或 Tensor): 要變換的影像。

返回值:

仿射變換後的影像。

返回型別:

PIL Image 或 Tensor

static get_params(degrees: List[float], translate: Optional[List[float]], scale_ranges: Optional[List[float]], shears: Optional[List[float]], img_size: List[int]) Tuple[float, Tuple[int, int], float, Tuple[float, float]][源]

獲取仿射變換的引數

返回值:

要傳遞給仿射變換的引數

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深入教程

檢視教程

資源

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

檢視資源