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.NEAREST和InterpolationMode.BILINEAR。也接受相應的 Pillow 整數常量,例如PIL.Image.BILINEAR。fill (序列或數字) – 變換後圖像外部區域的畫素填充值。預設值為
0。如果給定一個數字,則該值將分別用於所有波段。center (序列, 可選) – 可選的旋轉中心,(x, y)。原點是左上角。預設是影像中心。
使用
RandomAffine的示例