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 operator.

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

>>> 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"])