mindspore.dataset.vision.MixUpBatch

class mindspore.dataset.vision.MixUpBatch(alpha=1.0)[source]

Apply MixUp transformation on input batch of images and labels. Each image is multiplied by a random weight (lambda) and then added to a randomly selected image from the batch multiplied by (1 - lambda). The same formula is also applied to the one-hot labels.

The lambda is generated based on the specified alpha value. Two coefficients x1, x2 are randomly generated in the range [alpha, 1], and lambda = (x1 / (x1 + x2)).

Note that you need to make labels into one-hot format and batched before calling this operation.

Parameters

alpha (float, optional) – Hyperparameter of beta distribution. The value must be positive. Default: 1.0.

Raises
  • TypeError – If alpha is not of type float.

  • ValueError – If alpha is not positive.

  • RuntimeError – If given tensor shape is not <N, H, W, C> or <N, C, H, W>.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> import mindspore.dataset.transforms as transforms
>>>
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> onehot_op = transforms.OneHot(num_classes=10)
>>> image_folder_dataset= image_folder_dataset.map(operations=onehot_op,
...                                                input_columns=["label"])
>>> mixup_batch_op = vision.MixUpBatch(alpha=0.9)
>>> image_folder_dataset = image_folder_dataset.batch(5)
>>> image_folder_dataset = image_folder_dataset.map(operations=mixup_batch_op,
...                                                 input_columns=["image", "label"])
Tutorial Examples: