mindspore.dataset.vision.py_transforms.MixUp

class mindspore.dataset.vision.py_transforms.MixUp(batch_size, alpha, is_single=True)[source]

Randomly mix up a batch of images together with its labels. Each image will be multiplied by a random weight lambda generated from the beta distribution and then added to another image multiplied by 1 - lambda. The same transformation will be applied to their labels with the same value of lambda. Make sure that the labels are one hot encoded in advance.

Parameters
  • batch_size (int) – The number of images in a batch.

  • alpha (float) – The alpha and beta parameter in the beta distribution.

  • is_single (bool, optional) – If True, it will randomly mix up [img(0), …, img(n-1), img(n)] with [img1, …, img(n), img0] in each batch. Otherwise, it will randomly mix up images with the output of mixing of previous batch of images (Default=True).

Examples

>>> # Setup multi-batch mixup transformation
>>> transform = [py_vision.MixUp(batch_size=16, alpha=0.2, is_single=False)]
>>> # Apply the transform to the dataset through dataset.map()
>>> image_folder_dataset = image_folder_dataset.map(input_columns="image",
...                                                 operations=transform)