mindspore.dataset.vision.RandomSelectSubpolicy

View Source On Gitee
class mindspore.dataset.vision.RandomSelectSubpolicy(policy)[source]

Choose a random sub-policy from a policy list to be applied on the input image.

Parameters

policy (list[list[tuple[TensorOperation, float]]]) – List of sub-policies to choose from. A sub-policy is a list of tuple[operation, prob], where operation is a data processing operation and prob is the probability that this operation will be applied, and the prob values must be in range [0.0, 1.0]. Once a sub-policy is selected, each operation within the sub-policy with be applied in sequence according to its probability.

Raises

TypeError – If policy contains invalid data processing operations.

Supported Platforms:

CPU

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> # Use the transform in dataset pipeline mode
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
>>> policy = [[(vision.RandomRotation((45, 45)), 0.5),
...            (vision.RandomVerticalFlip(), 1),
...            (vision.RandomColorAdjust(), 0.8)],
...           [(vision.RandomRotation((90, 90)), 1),
...            (vision.RandomColorAdjust(), 0.2)]]
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=vision.RandomSelectSubpolicy(policy),
...                                                 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
(100, 100, 3) uint8
>>>
>>> # Use the transform in eager mode
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
>>> policy = [[(vision.RandomRotation((90, 90)), 1), (vision.RandomColorAdjust(), 1)]]
>>> output = vision.RandomSelectSubpolicy(policy)(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples: