mindspore.dataset.vision.AutoAugment
- class mindspore.dataset.vision.AutoAugment(policy=AutoAugmentPolicy.IMAGENET, interpolation=Inter.NEAREST, fill_value=0)[源代码]
应用AutoAugment数据增强方法,基于论文 AutoAugment: Learning Augmentation Strategies from Data 。 此操作仅适用于3通道RGB图像。
- 参数:
policy (
AutoAugmentPolicy, 可选) - 在不同数据集上学习的AutoAugment策略。默认值:AutoAugmentPolicy.IMAGENET。 可以是AutoAugmentPolicy.IMAGENET、AutoAugmentPolicy.CIFAR10、AutoAugmentPolicy.SVHN。AutoAugmentPolicy.IMAGENET:表示应用在ImageNet数据集上学习的AutoAugment。
AutoAugmentPolicy.CIFAR10:表示应用在Cifar10数据集上学习的AutoAugment。
AutoAugmentPolicy.SVHN:表示应用在SVHN数据集上学习的AutoAugment。
interpolation (
Inter, 可选) - 图像插值方法。可选值详见mindspore.dataset.vision.Inter。 默认值:Inter.NEAREST。fill_value (Union[int, tuple[int]], 可选) - 填充的像素值。 如果是3元素元组,则分别用于填充R、G、B通道。 如果是整数,则用于所有 RGB 通道。 fill_value 值必须在 [0, 255] 范围内。默认值:
0。
- 异常:
TypeError - 如果 policy 不是
mindspore.dataset.vision.AutoAugmentPolicy类型。TypeError - 如果 interpolation 不是
mindspore.dataset.vision.Inter类型。TypeError - 如果 fill_value 不是整数或长度为3的元组。
RuntimeError - 如果给定的张量shape不是<H, W, C>。
- 支持平台:
CPU
样例:
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.vision import AutoAugmentPolicy, Inter >>> >>> # Use the transform in dataset pipeline mode >>> transforms_list = [vision.AutoAugment(policy=AutoAugmentPolicy.IMAGENET, ... interpolation=Inter.NEAREST, ... fill_value=0)] >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, 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) >>> output = vision.AutoAugment()(data) >>> print(output.shape, output.dtype) (100, 100, 3) uint8
- 教程样例: