mindspore.dataset.transforms.RandomChoice

View Source On Gitee
class mindspore.dataset.transforms.RandomChoice(transforms)[source]

Randomly select one transform from a list of transforms to perform operation.

Parameters

transforms (list) – List of transformations to be chosen from to apply.

Raises
  • TypeError – If transforms is not of type list.

  • ValueError – If transforms is empty.

  • TypeError – If elements of transforms are neither Python callable objects nor data processing operations in transforms.py.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.transforms as transforms
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.transforms import Compose
>>>
>>> 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([vision.Decode(),
...                               transforms.RandomChoice(transforms_list),
...                               vision.ToTensor()])
>>>
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=composed_transform, input_columns=["image"])