Shortcuts

随机旋转

class torchvision.transforms.RandomRotation(degrees, interpolation=InterpolationMode.NEAREST, expand=False, center=None, fill=0)[source]

旋转图像的角度。 如果图像是torch张量,它应该具有[…, H, W]形状,其中…表示任意数量的前导维度。

Parameters:
  • degrees (sequencenumber) – 选择的角度范围。 如果 degrees 是一个数字而不是像 (min, max) 这样的序列,那么角度范围将是 (-degrees, +degrees)。

  • 插值 (InterpolationMode) – 由torchvision.transforms.InterpolationMode定义的所需插值枚举。默认值为InterpolationMode.NEAREST。 如果输入是张量,则仅支持InterpolationMode.NEARESTInterpolationMode.BILINEAR。 也接受相应的Pillow整数常量,例如PIL.Image.BILINEAR

  • expand (bool, optional) – 可选的扩展标志。 如果为true,则扩展输出以使其足够大以容纳整个旋转后的图像。 如果为false或省略,则使输出图像与输入图像大小相同。 请注意,expand标志假设围绕中心旋转且没有平移。

  • center (sequence, optional) – 可选的旋转中心,(x, y)。原点是左上角。 默认是图像的中心。

  • fill (sequencenumber) – 旋转图像外部区域的像素填充值。默认值为 0。如果给定一个数字,则该值将分别用于所有波段。

使用 RandomRotation 的示例:

变换的图示

Illustration of transforms
forward(img)[source]
Parameters:

img (PIL ImageTensor) – 要旋转的图像。

Returns:

旋转后的图像。

Return type:

PIL 图像或张量

static get_params(degrees: List[float]) float[source]

获取用于随机旋转的rotate参数。

Returns:

传递给rotate的随机旋转角度参数。

Return type:

float