yamle.data.augmentations module#
- class yamle.data.augmentations.Augmentation(batch_proportion)[source]#
Bases:
ABCThis is a base class for all augmentations. It is an abstract class and should not be used directly. Instead, use one of the concrete subclasses.
- Parameters:
batch_proportion¶ (float) – The proportion of the batch to augment.
- class yamle.data.augmentations.MixUp(alpha, *args, **kwargs)[source]#
Bases:
AugmentationThis is an implementation of the MixUp augmentation, as described in https://arxiv.org/abs/1710.09412.
- Parameters:
alpha¶ (float) – The alpha parameter for the beta distribution used to sample the mixup weights.
- augment(inputs, targets, model)[source]#
Applies the MixUp augmentation to the inputs and returns the augmented inputs.
The targets are assumed to be one-hot encoded.
It is applied such that:
l ~ Beta(alpha, alpha) x’ = l * x + (1 - l) * x’ y’ = l * y + (1 - l) * y’ where x’ and y’ are the randomly shuffled inputs and targets, respectively.
- Return type:
Tuple[Tensor,Tensor]
- class yamle.data.augmentations.CutOut(batch_proportion, size)[source]#
Bases:
AugmentationThis is an implementation of the CutOut augmentation, as described in https://arxiv.org/abs/1708.04552.
- Parameters:
- augment(inputs, targets, model)[source]#
Applies the CutOut augmentation to the inputs and returns the augmented inputs.
The targets are not modified.
It is applied such that a square region of size size is randomly cut out from each input image.
- Parameters:
- Return type:
Tuple[Tensor,Tensor]- Returns:
Tuple[torch.Tensor, torch.Tensor] – The augmented inputs and unchanged targets.
- class yamle.data.augmentations.CutMix(batch_proportion, alpha)[source]#
Bases:
AugmentationThis is an implementation of CutMix augmentation, as described in the paper: https://arxiv.org/abs/1905.04899.
- Parameters:
- augment(inputs, targets, model)[source]#
Applies the CutMix augmentation to the inputs and returns the augmented inputs and targets.
The targets are assumed to be one-hot encoded.
It is applied such that: - Two random inputs are selected for combining. - A random box is cut out from one input and replaced with the corresponding box from another input. - The targets are adjusted to match the pixel ratio.
- class yamle.data.augmentations.RandomErasing(batch_proportion, scale, ratio, value=0)[source]#
Bases:
AugmentationThis is a wrapper class for the RandomErasing augmentation provided by torchvision.
- Parameters:
batch_proportion¶ (float) – The proportion of the batch to augment.
scale¶ (Tuple[float, float]) – The range of the proportion of erased area against the input image.
ratio¶ (Tuple[float, float]) – The range of the aspect ratio of the erased area.
value¶ (int or tuple or str) – The erasing value. Default is 0. - If an integer, it is used to erase all pixels. - If a tuple of length 3, it is used to erase R, G, B channels respectively. - If a string ‘random’, each pixel is erased with random values.