RandomAffine¶
- class torchvision.transforms.v2.RandomAffine(degrees: Union[Number, Sequence], translate: Optional[Sequence[float]] = None, scale: Optional[Sequence[float]] = None, shear: Optional[Union[int, float, Sequence[float]]] = None, interpolation: Union[InterpolationMode, int] = InterpolationMode.NEAREST, fill: Union[int, float, Sequence[int], Sequence[float], None, Dict[Union[Type, str], Optional[Union[int, float, Sequence[int], Sequence[float]]]]] = 0, center: Optional[List[float]] = None)[source]¶
隨機仿射轉換輸入,保持中心不變。
如果輸入是
torch.Tensor
或TVTensor
(例如Image
,Video
,BoundingBoxes
等),它可以具有任意數量的 leading batch 維度。例如,影像可以具有[..., C, H, W]
形狀。邊界框可以具有[..., 4]
形狀。- 參數:
degrees (序列 或 數字) – 要從中選擇的角度範圍。如果 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),然後 scale 從 a <= scale <= b 範圍內隨機取樣。預設情況下保持原始比例。
shear (sequence 或 number, 選填) – 要選取的錯切角度範圍。如果 shear 是一個數字,則會應用在 (-shear, +shear) 範圍內與 x 軸平行的錯切。如果 shear 是一個包含 2 個值的序列,則會應用在 (shear[0], shear[1]) 範圍內與 x 軸平行的錯切。如果 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 (number 或 tuple 或 dict, 選填) – 當
padding_mode
為常數時,使用的像素填充值。預設值為 0。如果是一個長度為 3 的 tuple,則分別用於填充 R、G、B 通道。填充值也可以是一個將資料類型映射到填充值的字典,例如fill={tv_tensors.Image: 127, tv_tensors.Mask: 0}
,其中Image
將被填充為 127,而Mask
將被填充為 0。center (sequence, 選填) – 旋轉的中心點 (x, y)。原點是左上角。預設值是圖片的中心。
使用
RandomAffine
的範例