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
的示例