mindspore.dataset.vision.py_transforms.RandomResizedCrop

class mindspore.dataset.vision.py_transforms.RandomResizedCrop(size, scale=(0.08, 1.0), ratio=(3.0 / 4.0, 4.0 / 3.0), interpolation=Inter.BILINEAR, max_attempts=10)[source]

Randomly crop the input PIL Image and resize it to a given size.

Parameters
  • size (Union[int, Sequence[int, int]]) – The size of the cropped image. If int is provided, a square of size (size, size) will be cropped with this value. If Sequence[int, int] is provided, its two elements will be taken as the cropped height and width.

  • scale (Sequence[float, float], optional) – Range of area scale of the cropped area relative to the original image to select from, arraged in order or (min, max). Default: (0.08, 1.0).

  • ratio (Sequence[float, float], optional) – Range of aspect ratio of the cropped area to select from, arraged in order of (min, max). Default: (3./4., 4./3.).

  • interpolation (Inter, optional) –

    Method of interpolation. It can be Inter.NEAREST, Inter.ANTIALIAS, Inter.BILINEAR or Inter.BICUBIC. Default: Inter.BILINEAR.

    • Inter.NEAREST, nearest-neighbor interpolation.

    • Inter.ANTIALIAS, antialias interpolation.

    • Inter.BILINEAR, bilinear interpolation.

    • Inter.BICUBIC, bicubic interpolation.

  • max_attempts (int, optional) – The maximum number of attempts to propose a valid crop area, beyond which it will fall back to use center crop instead. Default: 10.

Raises
Supported Platforms:

CPU

Examples

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>>
>>> transforms_list = Compose([py_vision.Decode(),
...                            py_vision.RandomResizedCrop(224),
...                            py_vision.ToTensor()])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")