MixUp — Torchvision 0.22 documentation (original) (raw)

class torchvision.transforms.v2.MixUp(*, alpha: float = 1.0, num_classes: Optional[int] = None, labels_getter='default')[source]

Apply MixUp to the provided batch of images and labels.

Paper: mixup: Beyond Empirical Risk Minimization.

Note

This transform is meant to be used on batches of samples, not individual images. SeeHow to use CutMix and MixUp for detailed usage examples. The sample pairing is deterministic and done by matching consecutive samples in the batch, so the batch needs to be shuffled (this is an implementation detail, not a guaranteed convention.)

In the input, the labels are expected to be a tensor of shape (batch_size,). They will be transformed into a tensor of shape (batch_size, num_classes).

Parameters:

Examples using MixUp:

make_params(flat_inputs: List[Any]) → Dict[str, Any][source]

Method to override for custom transforms.

See How to write your own v2 transforms

transform(inpt: Any, params: Dict[str, Any]) → Any[source]

Method to override for custom transforms.

See How to write your own v2 transforms