RandomResizedCrop — Torchvision 0.22 documentation (original) (raw)

class torchvision.transforms.RandomResizedCrop(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=InterpolationMode.BILINEAR, antialias: Optional[bool] = True)[source]

Crop a random portion of image and resize it to a given size.

If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions

A crop of the original image is made: the crop has a random area (H * W) and a random aspect ratio. This crop is finally resized to the given size. This is popularly used to train the Inception networks.

Parameters:

Examples using RandomResizedCrop:

forward(img)[source]

Parameters:

img (PIL Image or Tensor) – Image to be cropped and resized.

Returns:

Randomly cropped and resized image.

Return type:

PIL Image or Tensor

static get_params(img: Tensor, scale: List[float], ratio: List[float]) → Tuple[int, int, int, int][source]

Get parameters for crop for a random sized crop.

Parameters:

Returns:

params (i, j, h, w) to be passed to crop for a random sized crop.

Return type:

tuple