mindspore.dataset.vision.RandomHorizontalFlipWithBBox

class mindspore.dataset.vision.RandomHorizontalFlipWithBBox(prob=0.5)[源代码]

按给定的概率,对输入图像及其边界框进行随机水平翻转。

参数:
  • prob (float, 可选) - 图像被翻转的概率,取值范围:[0.0, 1.0]。默认值: 0.5

异常:
  • TypeError - 如果 prob 不是float类型。

  • ValueError - 如果 prob 不在 [0.0, 1.0] 范围内。

  • 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=(100, 100, 3)).astype(np.float32)
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
...                                                 input_columns=["image"],
...                                                 output_columns=["image", "bbox"])
>>> transforms_list = [vision.RandomHorizontalFlipWithBBox(0.70)]
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list,
...                                                 input_columns=["image", "bbox"])
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["image"].shape, item["image"].dtype)
...     print(item["bbox"].shape, item["bbox"].dtype)
...     break
(100, 100, 3) float32
(1, 4) float32
>>>
>>> # Use the transform in eager mode
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(data.dtype))
>>> func_data, func_bboxes = func(data)
>>> output = vision.RandomHorizontalFlipWithBBox(1)(func_data, func_bboxes)
>>> print(output[0].shape, output[0].dtype)
(100, 100, 3) float32
>>> print(output[1].shape, output[1].dtype)
(1, 4) float32
教程样例: