RandomResizedCrop

class paddle.vision.transforms. RandomResizedCrop ( size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation='bilinear', keys=None ) [source]

Crop the input data to random size and aspect ratio. A crop of random size (default: of 0.08 to 1.0) of the original size and a random aspect ratio (default: of 3/4 to 1.33) of the original aspect ratio is made. After applying crop transform, the input data will be resized to given size.

Parameters
  • size (int|list|tuple) – Target size of output image, with (height, width) shape.

  • scale (list|tuple, optional) – Scale range of the cropped image before resizing, relatively to the origin image. Default: (0.08, 1.0).

  • ratio (list|tuple, optional) – Range of aspect ratio of the origin aspect ratio cropped. Default: (0.75, 1.33)

  • interpolation (int|str, optional) – Interpolation method. Default: ‘bilinear’. when use pil backend, support method are as following: - “nearest”: Image.NEAREST, - “bilinear”: Image.BILINEAR, - “bicubic”: Image.BICUBIC, - “box”: Image.BOX, - “lanczos”: Image.LANCZOS, - “hamming”: Image.HAMMING when use cv2 backend, support method are as following: - “nearest”: cv2.INTER_NEAREST, - “bilinear”: cv2.INTER_LINEAR, - “area”: cv2.INTER_AREA, - “bicubic”: cv2.INTER_CUBIC, - “lanczos”: cv2.INTER_LANCZOS4

  • keys (list[str]|tuple[str], optional) – Same as BaseTransform. Default: None.

Shape:
  • img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).

  • output(PIL.Image|np.ndarray|Paddle.Tensor): A cropped image.

Returns

A callable object of RandomResizedCrop.

Examples

>>> import numpy as np
>>> from PIL import Image
>>> from paddle.vision.transforms import RandomResizedCrop

>>> transform = RandomResizedCrop(224)
>>> fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8))
>>> fake_img = transform(fake_img)
>>> print(fake_img.size)
(224, 224)