mindspore.dataset.vision.RandomResizedCrop
- class mindspore.dataset.vision.RandomResizedCrop(size, scale=(0.08, 1.0), ratio=(3.0 / 4.0, 4.0 / 3.0), interpolation=Inter.BILINEAR, max_attempts=10)[source]
This operation will crop the input image randomly, and resize the cropped image using a selected interpolation mode
mindspore.dataset.vision.Inter
.Note
If the input image is more than one, then make sure that the image size is the same.
- Parameters
size (Union[int, Sequence[int]]) – The output size of the resized image. The size value(s) must be positive. If size is an integer, a square of size (size, size) will be cropped with this value. If size is a sequence of length 2, an image of size (height, width) will be cropped.
scale (Union[list, tuple], optional) – Range [min, max) of respective size of the original size to be cropped, which must be non-negative. Default: (0.08, 1.0).
ratio (Union[list, tuple], optional) – Range [min, max) of aspect ratio to be cropped, which must be non-negative. Default: (3. / 4., 4. / 3.).
interpolation (Inter, optional) –
Method of interpolation. Default: Inter.BILINEAR. It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC, Inter.AREA, Inter.PILCUBIC].
Inter.BILINEAR, means interpolation method is bilinear interpolation.
Inter.NEAREST, means interpolation method is nearest-neighbor interpolation.
Inter.BICUBIC, means interpolation method is bicubic interpolation.
Inter.AREA, means interpolation method is pixel area interpolation.
Inter.PILCUBIC, means interpolation method is bicubic interpolation like implemented in pillow, input should be in 3 channels format.
Inter.ANTIALIAS, means the interpolation method is antialias 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 int or Sequence[int].
TypeError – If scale is not of type tuple or list.
TypeError – If ratio is not of type tuple or list.
TypeError – If interpolation is not of type
mindspore.dataset.vision.Inter
.TypeError – If max_attempts is not of type int.
ValueError – If size is not positive.
ValueError – If scale is negative.
ValueError – If ratio is negative.
ValueError – If max_attempts is not positive.
RuntimeError – If given tensor shape is not <H, W> or <…, H, W, C>.
- Supported Platforms:
CPU
Examples
>>> from mindspore.dataset.vision import Inter >>> decode_op = vision.Decode() >>> resize_crop_op = vision.RandomResizedCrop(size=(50, 75), scale=(0.25, 0.5), ... interpolation=Inter.BILINEAR) >>> transforms_list = [decode_op, resize_crop_op] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])