peal.training.trainers.mixup

peal.training.trainers.mixup(data, targets, alpha, n_classes)[source]

Mix each sample with a random partner (Zhang et al. mixup).

Parameters:
  • data (torch.Tensor) – Input batch of shape (B, ...).

  • targets (torch.Tensor) – Integer class labels of shape (B,).

  • alpha (float) – Beta distribution parameter; one lam ~ Beta(alpha, alpha) is drawn for the whole batch.

  • n_classes (int) – Width of the one-hot targets.

Returns:

(mixed_data, mixed_onehot_targets) with targets of shape (B, n_classes).

Return type:

tuple of torch.Tensor