随机透视¶
- class torchvision.transforms.RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=InterpolationMode.BILINEAR, fill=0)[source]¶
对给定图像以给定概率执行随机透视变换。 如果图像是torch张量,则期望其具有[…, H, W]形状,其中…表示任意数量的前导维度。
- Parameters:
distortion_scale (float) – 用于控制失真程度的参数,范围从0到1。 默认值为0.5。
p (float) – 图像被转换的概率。默认值为0.5。
插值 (InterpolationMode) – 由
torchvision.transforms.InterpolationMode定义的期望插值枚举。默认是InterpolationMode.BILINEAR。 如果输入是张量,仅支持InterpolationMode.NEAREST,InterpolationMode.BILINEAR。 相应的Pillow整数常量,例如PIL.Image.BILINEAR也被接受。fill (sequence 或 number) – 变换图像外部区域的像素填充值。默认值为
0。如果给定一个数字,则该值将分别用于所有波段。
使用
RandomPerspective的示例:- forward(img)[source]¶
- Parameters:
img (PIL Image 或 Tensor) – 需要进行透视变换的图像。
- Returns:
随机变换的图像。
- Return type:
PIL 图像或张量