mindspore.dataset.vision.RandomHorizontalFlip
- class mindspore.dataset.vision.RandomHorizontalFlip(prob=0.5)[source]
Randomly flip the input image horizontally with a given probability.
- Parameters
prob (float, optional) – Probability of the image being flipped, which must be in range of [0.0, 1.0]. Default:
0.5
.- Raises
TypeError – If prob is not of type float.
ValueError – If prob is not in range [0.0, 1.0].
RuntimeError – If given tensor shape is not <H, W> or <H, W, C>.
- Supported Platforms:
CPU
Examples
>>> 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.RandomHorizontalFlip(0.75)] >>> 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.RandomHorizontalFlip(1.0)(data) >>> print(output.shape, output.dtype) (100, 100, 3) uint8
- Tutorial Examples: