捷徑

RandomAffine

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

隨機仿射變換影像,保持中心不變。如果影像是 torch Tensor,則預期具有 […, H, W] 形狀,其中 … 表示任意數量的 leading dimension。

參數:
  • degrees (sequence or number) – 要從中選擇的角度範圍。如果 degrees 是一個數字而不是像 (min, max) 這樣的序列,則角度範圍將為 (-degrees, +degrees)。設定為 0 可停用旋轉。

  • translate (tuple, optional) – 水平和垂直平移的最大絕對分數的 tuple。例如,translate=(a, b),則水平位移在範圍 -img_width * a < dx < img_width * a 中隨機取樣,垂直位移在範圍 -img_height * b < dy < img_height * b 中隨機取樣。預設不會平移。

  • scale (tuple, optional) – 縮放比例的區間,例如 (a, b),則縮放比例會從 a <= scale <= b 的範圍中隨機取樣。預設為保持原始縮放比例。

  • shear (sequence or number, optional) – 選擇角度的範圍。如果 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 (sequence or number) – 轉換後圖像外部區域的像素填充值。預設值為 0。如果給定一個數字,則該值將分別用於所有通道。

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

使用 RandomAffine 的範例

變換的說明

變換的說明
forward(img)[source]

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]][source]

取得仿射變換的參數

傳回:

要傳遞給仿射變換的參數

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深度教學

檢視教學

資源

尋找開發資源並獲得您的問題解答

檢視資源