mindspore.dataset.vision.UniformAugment
- class mindspore.dataset.vision.UniformAugment(transforms, num_ops=2)[source]
Uniformly select a number of transformations from a sequence and apply them sequentially and randomly, which means that there is a chance that a chosen transformation will not be applied.
All transformations in the sequence require the output type to be the same as the input. Thus, the latter one can deal with the output of the previous one.
- Parameters
transforms (Sequence) – Sequence of transformations to select from.
num_ops (int, optional) – Number of transformations to be sequentially and randomly applied. Default:
2
.
- Raises
TypeError – If transforms is not a sequence of data processing operations.
TypeError – If num_ops is not of type integer.
ValueError – If num_ops is not positive.
- Supported Platforms:
CPU
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.transforms import Compose >>> >>> # Use the transform in dataset pipeline mode >>> seed = ds.config.get_seed() >>> ds.config.set_seed(12345) >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> transform = [vision.CenterCrop(64), ... vision.RandomColor(), ... vision.RandomSharpness(), ... vision.RandomRotation(30)] >>> transforms_list = Compose([vision.UniformAugment(transform), ... vision.ToTensor()]) >>> # apply the transform to dataset through map function >>> 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 (3, 100, 100) float32 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> transform = [vision.RandomCrop(size=[20, 40], padding=[32, 32, 32, 32]), ... vision.RandomCrop(size=[20, 40], padding=[32, 32, 32, 32])] >>> output = vision.UniformAugment(transform)(data) >>> print(output.shape, output.dtype) (20, 40, 3) uint8 >>> ds.config.set_seed(seed)
- Tutorial Examples: