Shortcuts

随机透视

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], Optional[Union[int, float, Sequence[int], Sequence[float]]]]] = 0)[source]

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

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

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

  • p (float, 可选) – 输入被转换的概率。默认值为0.5。

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

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

使用 RandomPerspective 的示例:

变换的图示

Illustration of transforms
static get_params(width: int, height: int, distortion_scale: float) Tuple[List[List[int]], List[List[int]]][source]

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

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

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

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

Returns:

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