快捷方式

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.NEARESTInterpolationMode.BILINEAR。也接受相应的 Pillow 整数常量,例如 PIL.Image.BILINEAR

  • fill (sequence or number) – 变换后图像区域的像素填充值。默认为 0。如果给出数字,则该值分别用于所有通道。

使用 RandomPerspective 的示例

转换图示

转换图示
forward(img)[source]
参数:

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

返回:

随机变换后的图像。

返回类型:

PIL 图像或张量

static get_params(width: int, height: int, distortion_scale: float) tuple[list[list[int]], list[list[int]]][source]

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

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

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

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

返回:

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

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源