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