mindspore.dataset.vision.ResizedCrop
- class mindspore.dataset.vision.ResizedCrop(top, left, height, width, size, interpolation=Inter.BILINEAR)[source]
Crop the input image at a specific region and resize it to desired size.
Supports Ascend hardware acceleration and can be enabled through the .device("Ascend") method.
- Parameters
top (int) – Horizontal ordinate of the upper left corner of the crop region.
left (int) – Vertical ordinate of the upper left corner of the crop region.
height (int) – Height of the crop region.
width (int) – Width of the cropp region.
size (Union[int, Sequence[int, int]]) – The size of the output image. If int is provided, the smaller edge of the image will be resized to this value, keeping the image aspect ratio the same. If Sequence[int, int] is provided, it should be (height, width).
interpolation (Inter, optional) – Image interpolation method defined by
Inter
. Default:Inter.BILINEAR
.
- Raises
TypeError – If top is not of type int.
ValueError – If top is negative.
TypeError – If left is not of type int.
ValueError – If left is negative.
TypeError – If height is not of type int.
ValueError – If height is not positive.
TypeError – If width is not of type int.
ValueError – If width is not positive.
TypeError – If size is not of type int or Sequence[int, int].
ValueError – If size is not posotive.
RuntimeError – If shape of the input image is not <H, W> or <H, W, C>.
- Supported Platforms:
CPU
Ascend
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.vision import Inter >>> >>> # Use the transform in dataset pipeline mode >>> transforms_list = [vision.ResizedCrop(0, 0, 64, 64, (100, 75), Inter.BILINEAR)] >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... break (100, 75, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.ResizedCrop(0, 0, 1, 1, (5, 5), Inter.BILINEAR)(data) >>> print(output.shape, output.dtype) (5, 5, 3) uint8
- Tutorial Examples:
- device(device_target='CPU')[source]
Set the device for the current operator execution.
When the device is Ascend, input type supports uint8 and float32, input channel supports 1 and 3. The input data has a height limit of [4, 32768] and a width limit of [6, 32768].
- Parameters
device_target (str, optional) – The operator will be executed on this device. Currently supports
CPU
andAscend
. Default:CPU
.- Raises
TypeError – If device_target is not of type str.
ValueError – If device_target is not within the valid set of ['CPU', 'Ascend'].
- Supported Platforms:
CPU
Ascend
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.vision import Inter >>> >>> # Use the transform in dataset pipeline mode >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> resize_crop_op = vision.ResizedCrop(0, 0, 64, 64, (100, 75)).device("Ascend") >>> transforms_list = [resize_crop_op] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... break (100, 75, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.ResizedCrop(0, 0, 64, 64, (32, 16), Inter.BILINEAR).device("Ascend")(data) >>> print(output.shape, output.dtype) (32, 16, 3) uint8
- Tutorial Examples: