mindspore.dataset.transforms.RandomOrder
- class mindspore.dataset.transforms.RandomOrder(transforms)[source]
Perform a series of transforms to the input image in a random order.
- Parameters
transforms (list) – List of the transformations to apply.
- Raises
TypeError – If transforms is not of type list.
TypeError – If elements of transforms are neither Python callable objects nor data processing operations in mindspore.dataset.transforms.transforms.
ValueError – If transforms is empty.
- Supported Platforms:
CPU
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.transforms as transforms >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.transforms import Compose, Relational >>> >>> # Use the transform in dataset pipeline mode >>> seed = ds.config.get_seed() >>> ds.config.set_seed(12345) >>> transforms_list = [vision.RandomHorizontalFlip(0.5), ... vision.Normalize((0.491, 0.482, 0.447), (0.247, 0.243, 0.262)), ... vision.RandomErasing()] >>> composed_transform = Compose([transforms.RandomOrder(transforms_list), ... vision.ToTensor()]) >>> >>> 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=composed_transform, 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.array([1, 2, 3]) >>> output = transforms.RandomOrder([transforms.Mask(Relational.EQ, 100)])(data) >>> print(output.shape, output.dtype) (3,) bool >>> ds.config.set_seed(seed)