albumentations.batch.mixup
Sample and apply MixUp plans for tensors with a leading batch axis.
Members
- classMixUpPlan
- functionsample_mixup
- functionapply_mixup
MixUpPlanclass
MixUpPlan()Donor indices and original-sample weights for a batch.
sample_mixupfunction
sample_mixup(
batch_size: int,
alpha: float,
device: torch.device,
generator: torch.Generator,
mode: MixingMode = pair
)Draw a donor index and a Beta(alpha, alpha) weight for each sample. Args: batch_size (int): Number of samples in the batch. alpha (float): Finite positive concentration for the symmetric Beta distribution. device (torch.device): Device of the input batch and generator. generator (torch.Generator): Random generator used for both pairing and weights. mode (MixingMode): "pair" swaps randomly paired samples with independent weights, "element" permutes samples with independent weights, and "batch" swaps randomly paired samples with one shared weight. An unpaired sample keeps itself with weight 1. Returns: MixUpPlan: Donor indices and weights on the specified device. Raises: ValueError: If the batch size is nonpositive, alpha is invalid, or the mode is unsupported.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| batch_size | int | - | - |
| alpha | float | - | - |
| device | torch.device | - | - |
| generator | torch.Generator | - | - |
| mode | MixingMode | pair | - |
apply_mixupfunction
apply_mixup(
values: torch.Tensor,
plan: MixUpPlan
)Interpolate each sample with its donor along the batch axis. MixUp runs outside autograd. Args: values (torch.Tensor): Tensor with the batch axis first, such as BCHW or BCDHW. plan (MixUpPlan): Donor indices and weights for every sample on the input device. Returns: torch.Tensor: A tensor with the input shape and dtype. Interpolation uses FP32. Uint8 results are rounded to the nearest integer (ties to even) and clipped to [0, 255]. Raises: ValueError: If the input has no batch axis or the plan lengths differ from the batch size.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| values | torch.Tensor | - | - |
| plan | MixUpPlan | - | - |