快捷方式

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 (sequencenumber) – 变换图像外部区域的像素填充值。默认值为 0。如果给定一个数字,则该值用于所有通道。

使用 RandomPerspective 的示例

变换图示

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

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

返回:

随机变换后的图像。

返回类型:

PIL Image 或 Tensor

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 的全面开发者文档

查看文档

教程

获取针对初学者和高级开发者的深入教程

查看教程

资源

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

查看资源