快捷方式

RandomPerspective

class torchvision.transforms.v2.RandomPerspective(distortion_scale: float = 0.5, p: float = 0.5, interpolation: Union[InterpolationMode, int] = InterpolationMode.BILINEAR, fill: Union[int, float, Sequence[int], Sequence[float], None, dict[Union[type, str], Union[int, float, collections.abc.Sequence[int], collections.abc.Sequence[float], NoneType]] = 0)[源代码]

以给定的概率对输入执行随机透视变换。

如果输入是 torch.TensorTVTensor(例如 ImageVideoBoundingBoxes 等),它可以具有任意数量的前导批次维度。例如,图像可以具有 [..., C, H, W] 的形状。边界框可以具有 [..., 4] 的形状。

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

  • p (float, optional) – 输入被变换的概率。默认为 0.5。

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

  • fill (numbertupledict, optional) – 当 padding_mode 为 constant 时使用的像素填充值。默认为 0。如果为长度为 3 的元组,则分别用于填充 R、G、B 通道。填充值也可以是映射数据类型到填充值的字典,例如 fill={tv_tensors.Image: 127, tv_tensors.Mask: 0},其中 Image 将填充为 127,Mask 将填充为 0。

使用 RandomPerspective 的示例

转换图示

转换图示
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。

返回:

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

make_params(flat_inputs: list[Any]) dict[str, Any][源代码]

用于覆盖自定义变换的方法。

请参阅 如何编写自己的 v2 变换

transform(inpt: Any, params: dict[str, Any]) Any[源代码]

用于覆盖自定义变换的方法。

请参阅 如何编写自己的 v2 变换

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源