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 image and resize it to a given size.

Parameters
  • size (Union[int, sequence]) – The size of the output image. If size is an integer, a square of size (size, size) is returned. If size is a sequence of length 2, it should be in shape of (height, width).

  • scale (Union[list, tuple], optional) – Respective size range of the original image to be cropped in shape of (min, max) (default=(0.08, 1.0)).

  • ratio (Union[list, tuple], optional) – Aspect ratio range to be cropped in shape of (min, max) (default=(3./4., 4./3.)).

  • interpolation (Inter, optional) –

    Image interpolation mode (default=Inter.BILINEAR). It can be any of [Inter.NEAREST, Inter.ANTIALIAS, Inter.BILINEAR, Inter.BICUBIC].

    • 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 (default=10). If exceeded, fall back to use center crop instead.

Raises
  • TypeError – If size is not of type integer or sequence of integer.

  • TypeError – If scale is not of type tuple.

  • TypeError – If ratio is not of type tuple.

  • TypeError – If interpolation is not of type Inter.

  • TypeError – If max_attempts is not of type integer.

  • ValueError – If size is not positive.

  • ValueError – If scale is negative.

  • ValueError – If ratio is negative.

  • ValueError – If max_attempts is not positive.

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")