mindspore.dataset.vision.Rotate

class mindspore.dataset.vision.Rotate(degrees, resample=Inter.NEAREST, expand=False, center=None, fill_value=0)[source]

Rotate the input image by specified degrees.

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

Parameters
  • degrees (Union[int, float]) – Rotation degrees.

  • resample (Inter, optional) – Image interpolation method defined by Inter . Default: Inter.NEAREST.

  • expand (bool, optional) – Optional expansion flag. Default: False. If set to True, expand the output image to make it large enough to hold the entire rotated image. If set to False or omitted, make the output image the same size as the input. Note that the expand flag assumes rotation around the center and no translation.

  • center (tuple, optional) – Optional center of rotation (a 2-tuple). Default: None. Origin is the top left corner. None sets to the center of the image.

  • fill_value (Union[int, tuple[int]], optional) – Optional fill color for the area outside the rotated image. If it is a 3-tuple, it is used to fill R, G, B channels respectively. If it is an integer, it is used for all RGB channels. The fill_value values must be in range [0, 255]. Default: 0.

Raises
  • TypeError – If degrees is not of type integer, float or sequence.

  • TypeError – If resample is not of type Inter .

  • TypeError – If expand is not of type bool.

  • TypeError – If center is not of type tuple.

  • TypeError – If fill_value is not of type int or tuple[int].

  • ValueError – If fill_value is not in range [0, 255].

  • RuntimeError – If given tensor shape 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.Rotate(degrees=30.0, resample=Inter.NEAREST, expand=True)]
>>> 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
(137, 137, 3) uint8
>>>
>>> # Use the transform in eager mode
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
>>> output = vision.Rotate(degrees=30.0, resample=Inter.NEAREST, expand=True)(data)
>>> print(output.shape, output.dtype)
(137, 137, 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/float32, input channel supports 1 and 3. The input data has a height limit of [4, 8192] and a width limit of [6, 4096].

  • When the device is Ascend and expand is True, center does not take effect and the image is rotated according to the center of the image.

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
>>> data = np.random.randint(0, 255, size=(1, 300, 400, 3)).astype(np.uint8)
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
>>> rotate_op = vision.Rotate(degrees=90.0, resample=Inter.NEAREST, expand=True).device("Ascend")
>>> transforms_list = [rotate_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
(400, 300, 3) uint8
>>>
>>> # Use the transform in eager mode
>>> data = np.random.randint(0, 255, size=(300, 400, 3)).astype(np.uint8)
>>> output = vision.Rotate(degrees=90.0, resample=Inter.NEAREST, expand=True).device("Ascend")(data)
>>> print(output.shape, output.dtype)
(400, 300, 3) uint8
Tutorial Examples: