mindspore.dataset.transforms.RandomApply

View Source On Gitee
class mindspore.dataset.transforms.RandomApply(transforms, prob=0.5)[source]

Randomly perform a series of transforms with a given probability.

Parameters
  • transforms (list) – List of transformations to be applied.

  • prob (float, optional) – The probability to apply the transformation list. Default: 0.5.

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.

  • TypeError – If prob is not of type float.

  • ValueError – If prob is not in range [0.0, 1.0].

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(to_pil=True),
...                               transforms.RandomApply(transforms_list, prob=0.6),
...                               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"])