mindspore.dataset.transforms.RandomOrder
- class mindspore.dataset.transforms.RandomOrder(transforms)[源代码]
给一个数据增强的列表,随机打乱数据增强处理的顺序。
- 参数:
transforms (list) - 一个数据增强的列表。
- 异常:
TypeError - 参数 transforms 类型不为list。
TypeError - 参数 transforms 的元素不是Python可调用对象或audio/text/transforms/vision模块中的数据处理操作。
ValueError - 参数 transforms 是空的list。
- 支持平台:
CPU
样例:
>>> 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)