mindspore.dataset.transforms.py_transforms.RandomApply

class mindspore.dataset.transforms.py_transforms.RandomApply(transforms, prob=0.5)[source]

Randomly perform a series of transforms with a given probability.

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

  • 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 py_transforms.

  • TypeError – If prob is not of type float.

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

Supported Platforms:

CPU

Examples

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>> transforms_list = [py_vision.RandomHorizontalFlip(0.5),
...                    py_vision.Normalize((0.491, 0.482, 0.447), (0.247, 0.243, 0.262)),
...                    py_vision.RandomErasing()]
>>> transforms = Compose([py_vision.Decode(),
...                       py_transforms.RandomApply(transforms_list, prob=0.6),
...                       py_vision.ToTensor()])
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms, input_columns=["image"])