快捷方式

RandomPerspective

class torchvision.transforms.RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=InterpolationMode.BILINEAR, fill=0)[源代码]

以给定的概率对给定图像执行随机透视变换。如果图像是 torch Tensor,则预期其形状为 […, H, W],其中 … 表示任意数量的前导维度。

参数:
  • distortion_scale (float) – 控制失真程度的参数,范围从 0 到 1。默认值为 0.5。

  • p (float) – 图像被变换的概率。默认值为 0.5。

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

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

使用 RandomPerspective 的示例

变换的图示

变换的图示
forward(img)[源代码]
参数:

img (PIL ImageTensor) – 要进行透视变换的图像。

返回:

随机变换后的图像。

返回类型:

PIL Image 或 Tensor

static get_params(width: int, height: int, distortion_scale: float) Tuple[List[List[int]], List[List[int]]][源代码]

获取随机透视变换的 perspective 参数。

参数:
  • width (int) – 图像的宽度。

  • height (int) – 图像的高度。

  • distortion_scale (float) – 控制失真程度的参数,范围从 0 到 1。

返回:

包含原始图像的 [左上角、右上角、右下角、左下角] 的列表,包含变换后图像的 [左上角、右上角、右下角、左下角] 的列表。

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得问题解答

查看资源