Shortcuts

RandomPerspective

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

Performs a random perspective transformation of the given image with a given probability. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions.

Parameters:
  • distortion_scale (float) – argument to control the degree of distortion and ranges from 0 to 1. Default is 0.5.

  • p (float) – probability of the image being transformed. Default is 0.5.

  • interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR. If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.BILINEAR are supported. The corresponding Pillow integer constants, e.g. PIL.Image.BILINEAR are accepted as well.

  • fill (sequence or number) – Pixel fill value for the area outside the transformed image. Default is 0. If given a number, the value is used for all bands respectively.

Examples using RandomPerspective:

Illustration of transforms

Illustration of transforms
forward(img)[source]
Parameters:

img (PIL Image or Tensor) – Image to be Perspectively transformed.

Returns:

Randomly transformed image.

Return type:

PIL Image or Tensor

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

Get parameters for perspective for a random perspective transform.

Parameters:
  • width (int) – width of the image.

  • height (int) – height of the image.

  • distortion_scale (float) – argument to control the degree of distortion and ranges from 0 to 1.

Returns:

List containing [top-left, top-right, bottom-right, bottom-left] of the original image, List containing [top-left, top-right, bottom-right, bottom-left] of the transformed image.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources