mindspore.dataset.vision.RandomSelectSubpolicy
- class mindspore.dataset.vision.RandomSelectSubpolicy(policy)[源代码]
从策略列表中随机选择一个子策略以应用于输入图像。
- 参数:
policy (list[list[tuple[TensorOperation, float]]]) - 可供选择的子策略列表。子策略是一系列 (operation, prob) 格式的元组组成的列表,其中 operation 是数据处理操作, prob 是应用此操作的概率, prob 值必须在 [0.0, 1.0] 范围内。一旦选择了子策略,子策略中的每个操作都将根据其概率依次应用。
- 异常:
TypeError - 当 policy 包含无效数据处理操作。
- 支持平台:
CPU
样例:
>>> 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
- 教程样例: