mindspore.dataset.vision.Resize

View Source On Gitee
class mindspore.dataset.vision.Resize(size, interpolation=Inter.LINEAR)[source]

Resize the input image to the given size with a given interpolation mode Inter .

Supports Ascend hardware acceleration and can be enabled through the .device("Ascend") method.

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, the smaller edge of the image will be resized to this value with the same image aspect ratio. If size is a sequence of length 2, it should be (height, width).

    • CPU mode: If the execution device is CPU by .device("CPU") , the range of size is [1, 16777216].

    • Ascend mode: set the executing device to Ascend by .device("Ascend") , the value of size will be in the range of [6, 32768].

  • interpolation (Inter, optional) –

    Image interpolation method defined by Inter . Default: Inter.LINEAR.

    • Ascend mode: Inter.ANTIALIAS , Inter.AREA , Inter.PILCUBIC interpolation methods are not supported when the execution device is set to Ascend by .device("Ascend") .

Raises
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_op = vision.Resize([100, 75], Inter.BICUBIC)
>>> transforms_list = [resize_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.Resize([5, 5], Inter.BICUBIC)(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/output shape should be limited from [4, 6] to [32768, 32768].

Parameters

device_target (str, optional) – The operator will be executed on this device. Currently supports "CPU" and "Ascend" . 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
>>> resize_op = vision.Resize([100, 75], Inter.BICUBIC).device("Ascend")
>>> transforms_list = [resize_op]
>>> 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.Resize([25, 25], Inter.BICUBIC).device("Ascend")(data)
>>> print(output.shape, output.dtype)
(25, 25, 3) uint8
Tutorial Examples: