composer.algorithms.functional.mixup_batch

composer.algorithms.functional.mixup_batch(x, y, interpolation_lambda, n_classes, indices=None)[source]

Implements mixup on a single batch of data.

This constructs a new batch of data given an original batch. This is done through the convex combination of x with a randomly permuted copy of x. The interploation parameter lambda should be chosen from a beta distribution with parameter alpha. Note that the same lambda is used for all examples within the batch.

Both the original and shuffled labels are returned. This is done because for many loss functions (such as cross entropy) the targets are given as indices, so interpolation must be handled separately.

Parameters
  • x (torch.Tensor) – Input tensor of shape (B, d1, d2, …, dn), B is batch size, d1-dn are feature dimensions.

  • y (torch.Tensor) – Target tensor of shape (B, f1, f2, …, fm), B is batch size, f1-fn are possible target dimensions.

  • interpolation_lambda (float) – Amount of interpolation based on alpha.

  • n_classes (int) – Total number of classes.

  • indices (Optional[torch.Tensor]) – Tensor of shape (B). Permutation of the batch indices. Used for permuting without randomness.

Returns
  • x_mix – Batch of inputs after mixup has been applied.

  • y_mix – Labels after mixup has been applied.