composer.algorithms.randaugment.randaugment#
Core RandAugment code.
Functions
Randomly applies a sequence of image data augmentations (Cubuk et al, 2019) to an image or batch of images. |
Classes
Randomly applies a sequence of image data augmentations (Cubuk et al, 2019) to an image. |
|
Wraps |
- class composer.algorithms.randaugment.randaugment.RandAugment(severity=9, depth=2, augmentation_set='all')[source]#
Bases:
composer.core.algorithm.Algorithm
Randomly applies a sequence of image data augmentations (Cubuk et al, 2019) to an image.
This algorithm runs on on
INIT
to insert a dataset transformation. It is a no-op if this algorithm already applied itself on theState.train_dataloader.dataset
.See the Method Card for more details.
Example
from composer.algorithms import RandAugment from composer.trainer import Trainer randaugment_algorithm = RandAugment( severity=9, depth=2, augmentation_set="all" ) trainer = Trainer( model=model, train_dataloader=train_dataloader, eval_dataloader=eval_dataloader, max_duration="1ep", algorithms=[randaugment_algorithm], optimizers=[optimizer] )
- Parameters
severity (int, optional) โ Severity of augmentation operators (between 1 to 10). M in the original paper. Default:
9
.depth (int, optional) โ Depth of augmentation chain. N in the original paper Default:
2
.augmentation_set (str, optional) โ
Must be one of the following options:
"augmentations_all"
Uses all augmentations from the paper.
"augmentations_corruption_safe"
Like
"augmentations_all"
, but excludes transforms that are part of the ImageNet-C/CIFAR10-C test sets
"augmentations_original"
Like
"augmentations_all"
, but some of the implementations are identical to the original Github repository, which contains implementation specificities for the augmentations"color"
,"contrast"
,"sharpness"
, and"brightness"
. The original implementations have an intensity sampling scheme that samples a value bounded by 0.118 at a minimum, and a maximum value of \(intensity \times 0.18 + .1\), which ranges from 0.28 (intensity = 1) to 1.9 (intensity 10). These augmentations have different effects depending on whether they are < 0 or > 0 (or < 1 or > 1). โaugmentations_allโ uses implementations of โcolorโ, โcontrastโ, โsharpnessโ, and โbrightnessโ that account for diverging effects around 0 (or 1).
Default:
"all"
.
- class composer.algorithms.randaugment.randaugment.RandAugmentTransform(severity=9, depth=2, augmentation_set='all')[source]#
Bases:
torch.nn.modules.module.Module
Wraps
randaugment_image()
in atorchvision
-compatible transform. SeeRandAugment
or the Method Card for more details.Example
import torchvision.transforms as transforms from composer.algorithms.randaugment import RandAugmentTransform randaugment_transform = RandAugmentTransform( severity=9, depth=2, augmentation_set="all" ) composed = transforms.Compose([randaugment_transform, transforms.RandomHorizontalFlip()]) transformed_image = composed(image)
- Parameters
severity (int, optional) โ See
RandAugment
.depth (int, optional) โ See
RandAugment
.augmentation_set (str, optional) โ See
RandAugment
.
- composer.algorithms.randaugment.randaugment.randaugment_image(img, severity=9, depth=2, augmentation_set=[<function autocontrast>, <function equalize>, <function posterize>, <function rotate>, <function solarize>, <function shear_x>, <function shear_y>, <function translate_x>, <function translate_y>, <function color>, <function contrast>, <function brightness>, <function sharpness>])[source]#
Randomly applies a sequence of image data augmentations (Cubuk et al, 2019) to an image or batch of images. See
RandAugment
or the Method Card for details. This function only acts on a single image (or batch of images) per call and is unlikely to be used in a training loop. UseRandAugmentTransform
to use RandAugment as part of atorchvision.datasets.VisionDataset
'stransform
.Example
import composer.functional as cf from composer.algorithms.utils import augmentation_sets randaugmented_image = cf.randaugment_image( img=image, severity=9, depth=2, augmentation_set=augmentation_sets["all"] )
- Parameters
img (Image | Tensor) โ Image or batch of images to be RandAugmented.
severity (int, optional) โ See
RandAugment
.depth (int, optional) โ See
RandAugment
.augmentation_set (str, optional) โ See
RandAugment
.
- Returns
PIL.Image โ RandAugmented image.