mindspore.dataset.vision.RandomCropDecodeResize
- class mindspore.dataset.vision.RandomCropDecodeResize(size, scale=(0.08, 1.0), ratio=(3.0 / 4.0, 4.0 / 3.0), interpolation=Inter.BILINEAR, max_attempts=10)[source]
A combination of Crop , Decode and Resize . It will get better performance for JPEG images. This operation will crop the input image at a random location, decode the cropped image in RGB mode, and resize the decoded image.
- 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 crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width).
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) – Image interpolation method defined by
Inter
. Default:Inter.BILINEAR
.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. The max_attempts value must be positive.
- Raises
TypeError – If size is not of type int or Sequence[int].
TypeError – If scale is not of type tuple.
TypeError – If ratio is not of type tuple.
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.
RuntimeError – If given tensor is not a 1D sequence.
- Supported Platforms:
CPU
Examples
>>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.vision import Inter >>> >>> resize_crop_decode_op = vision.RandomCropDecodeResize(size=(50, 75), ... scale=(0.25, 0.5), ... interpolation=Inter.NEAREST, ... max_attempts=5) >>> transforms_list = [resize_crop_decode_op] >>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory") >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns=["image"])
- Tutorial Examples: