<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/ops/augment.py#L2618-L2780) |

Applies Mixup and/or Cutmix to a batch of images.

    tfm.vision.augment.MixupAndCutmix(
        num_classes: int,
        mixup_alpha: float = 0.8,
        cutmix_alpha: float = 1.0,
        prob: float = 1.0,
        switch_prob: float = 0.5,
        label_smoothing: float = 0.1
    )

- Mixup: <https://arxiv.org/abs/1710.09412>
- Cutmix: <https://arxiv.org/abs/1905.04899>

Implementaion is inspired by <https://github.com/rwightman/pytorch-image-models>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `num_classes` | `int` <br /> Number of classes. |
| `mixup_alpha` | `float, optional` <br /> For drawing a random lambda (`lam`) from a beta distribution (for each image). If zero Mixup is deactivated. Defaults to .8. |
| `cutmix_alpha` | `float, optional` <br /> For drawing a random lambda (`lam`) from a beta distribution (for each image). If zero Cutmix is deactivated. Defaults to 1.. |
| `prob` | `float, optional` <br /> Of augmenting the batch. Defaults to 1.0. |
| `switch_prob` | `float, optional` <br /> Probability of applying Cutmix for the batch. Defaults to 0.5. |
| `label_smoothing` | `float, optional` <br /> Constant for label smoothing. Defaults to 0.1. |

<br />

## Methods

### `distort`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/ops/augment.py#L2669-L2696)

    distort(
        images: tf.Tensor, labels: tf.Tensor
    ) -> Tuple[tf.Tensor, tf.Tensor]

Applies Mixup and/or Cutmix to batch of images and transforms labels.

<br />

<br />

<br />

| Args ||
|---|---|
| `images` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) <br /> Of shape \[batch_size, height, width, 3\] representing a batch of image, or \[batch_size, time, height, width, 3\] representing a batch of video. |
| `labels` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) <br /> Of shape \[batch_size, \] representing the class id for each image of the batch. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Tuple\[tf.Tensor, tf.Tensor\]: The augmented version of `image` and `labels`. ||

<br />

### `__call__`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/ops/augment.py#L2665-L2667)

    __call__(
        images: tf.Tensor, labels: tf.Tensor
    ) -> Tuple[tf.Tensor, tf.Tensor]

Call self as a function.