mindspore.dataset.vision.MixUp
- class mindspore.dataset.vision.MixUp(batch_size, alpha, is_single=True)[source]
Randomly mix up a batch of numpy.ndarray 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 for the Beta distribution.
is_single (bool, optional) – If True, it will randomly mix up [img0, …, img(n-1), img(n)] with [img1, …, img(n), img0] in each batch. Otherwise, it will randomly mix up images with the output of the previous batch. Default: True.
- Raises
TypeError – If batch_size is not of type integer.
TypeError – If alpha is not of type float.
TypeError – If is_single is not of type boolean.
ValueError – If batch_size is not positive.
ValueError – If alpha is not positive.
- Supported Platforms:
CPU
Examples
>>> # first decode the image >>> image_folder_dataset = image_folder_dataset.map(operations=vision.Decode(), ... input_columns="image") >>> # then ont hot decode the label >>> image_folder_dataset = image_folder_dataset.map(operations=transforms.OneHot(10), ... input_columns="label") >>> # batch the samples >>> batch_size = 4 >>> image_folder_dataset = image_folder_dataset.batch(batch_size=batch_size) >>> # finally mix up the images and labels >>> image_folder_dataset = image_folder_dataset.map( ... operations=py_vision.MixUp(batch_size=batch_size, alpha=0.2), ... input_columns=["image", "label"])