mindspore.dataset.vision.VerticalFlip

class mindspore.dataset.vision.VerticalFlip[源代码]

对输入图像进行垂直翻转。

支持 Ascend 硬件加速,需要通过 .device(“Ascend”) 方式开启。

异常:
  • RuntimeError - 如果输入图像的shape不是 <H, W> 或 <…, H, W, C>。

支持平台:

CPU

样例:

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> # 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"])
>>> transforms_list = [vision.VerticalFlip()]
>>> 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, 100, 3) uint8
>>>
>>> # Use the transform in eager mode
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
>>> output = vision.VerticalFlip()(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
教程样例:
device(device_target='CPU')[源代码]

指定该变换执行的设备。

  • 当执行设备是 Ascend 时,输入数据的维度限制为[4, 6]和[8192, 4096]之间。

参数:
  • device_target (str, 可选) - 算子将在指定的设备上运行。当前支持 CPUAscend 。默认值: CPU

异常:
  • TypeError - 当 device_target 的类型不为str。

  • ValueError - 当 device_target 的取值不为 CPU / Ascend

支持平台:

CPU Ascend

样例:

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> # 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"])
>>> vertical_flip_op = vision.VerticalFlip().device("Ascend")
>>> transforms_list = [vertical_flip_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, 100, 3) uint8
>>>
>>> # Use the transform in eager mode
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
>>> output = vision.VerticalFlip().device("Ascend")(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8