RandomCrop — Torchvision 0.22 documentation (original) (raw)

class torchvision.transforms.RandomCrop(size, padding=None, pad_if_needed=False, fill=0, padding_mode='constant')[source]

Crop the given image at a random location. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions, but if non-constant padding is used, the input is expected to have at most 2 leading dimensions

Parameters:

Examples using RandomCrop:

forward(img)[source]

Parameters:

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

Returns:

Cropped image.

Return type:

PIL Image or Tensor

static get_params(img: Tensor, output_size: Tuple[int, int]) → Tuple[int, int, int, int][source]

Get parameters for crop for a random crop.

Parameters:

Returns:

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

Return type:

tuple