Augmenters that are collections of other augmenters.

List of augmenters:

Added in 0.4.0.

class imgaug.augmenters.collections.RandAugment(n=2, m=(6, 12), cval=128, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Sequential

Apply RandAugment to inputs as described in the corresponding paper.

See paper:

Cubuk et al.

RandAugment: Practical automated data augmentation with a reduced
search space


The paper contains essentially no hyperparameters for the individual augmentation techniques. The hyperparameters used here come mostly from the official code repository, which however seems to only contain code for CIFAR10 and SVHN, not for ImageNet. So some guesswork was involved and a few of the hyperparameters were also taken from .

This implementation deviates from the code repository for all PIL enhance operations. In the repository these use a factor of 0.1 + M*1.8/M_max, which would lead to a factor of 0.1 for the weakest M of M=0. For e.g. Brightness that would result in a basically black image. This definition is fine for AutoAugment (from where the code and hyperparameters are copied), which optimizes each transformation’s M individually, but not for RandAugment, which uses a single fixed M. We hence redefine these hyperparameters to 1.0 + S * M * 0.9/M_max, where S is randomly either 1 or -1.

We also note that it is not entirely clear which transformations were used in the ImageNet experiments. The paper lists some transformations in Figure 2, but names others in the text too (e.g. crops, flips, cutout). While Figure 2 lists the Identity function, this transformation seems to not appear in the repository (and in fact, the function randaugment(N, M) doesn’t seem to exist in the repository either). So we also make a best guess here about what transformations might have been used.


This augmenter only works with image data, not e.g. bounding boxes. The used PIL-based affine transformations are not yet able to process non-image data. (This augmenter uses PIL-based affine transformations to ensure that outputs are as similar as possible to the paper’s implementation.)

Added in 0.4.0.

Supported dtypes:

minimum of (
Fliplr, KeepSizeByResize, Crop, Sequential, SomeOf, Identity, Autocontrast, Equalize, Invert, Affine, Posterize, Solarize, EnhanceColor, EnhanceContrast, EnhanceBrightness, EnhanceSharpness, Cutout, FilterBlur, FilterSmooth



n (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or None, optional) – Parameter N in the paper, i.e. number of transformations to apply. The paper suggests N=2 for ImageNet. See also parameter n in SomeOf for more details.

Note that horizontal flips (p=50%) and crops are always applied. This parameter only determines how many of the other transformations are applied per image.

m : int or tuple of int or list of int or imgaug.parameters.StochasticParameter or None, optional

Parameter M in the paper, i.e. magnitude/severity/strength of the applied transformations in interval [0 .. 30] with M=0 being the weakest. The paper suggests for ImageNet M=9 in case of ResNet-50 and M=28 in case of EfficientNet-B7. This implementation uses a default value of (6, 12), i.e. the value is uniformly sampled per image from the interval [6 .. 12]. This ensures greater diversity of transformations than using a single fixed value.

  • If int: That value will always be used.
  • If tuple (a, b): A random value will be uniformly sampled per image from the discrete interval [a .. b].
  • If list: A random value will be picked from the list per image.
  • If StochasticParameter: For B images in a batch, B values will be sampled per augmenter (provided the augmenter is dependent on the magnitude).
cval : number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional

The constant value to use when filling in newly created pixels. See parameter fillcolor in Affine for details.

The paper’s repository uses an RGB value of 125, 122, 113. This implementation uses a single intensity value of 128, which should work better for cases where input images don’t have exactly 3 channels or come from a different dataset than used by the paper.

seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
See __init__().
name : None or str, optional
See __init__().
random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
deterministic : bool, optional
Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.


>>> import imgaug.augmenters as iaa
>>> aug = iaa.RandAugment(n=2, m=9)

Create a RandAugment augmenter similar to the suggested hyperparameters in the paper.

>>> aug = iaa.RandAugment(m=30)

Create a RandAugment augmenter with maximum magnitude/strength.

>>> aug = iaa.RandAugment(m=(0, 9))

Create a RandAugment augmenter that applies its transformations with a random magnitude between 0 (very weak) and 9 (recommended for ImageNet and ResNet-50). m is sampled per transformation.

>>> aug = iaa.RandAugment(n=(0, 3))

Create a RandAugment augmenter that applies 0 to 3 of its child transformations to images. Horizontal flips (p=50%) and crops are always applied.


__call__(self, *args, **kwargs) Alias for augment().
add(self, augmenter) Add an augmenter to the list of child augmenters.
append(self, object, /) Append object to the end of the list.
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
clear(self, /) Remove all items from list.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
count(self, value, /) Return number of occurrences of value.
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
extend(self, iterable, /) Extend list by appending elements from the iterable.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
index(self, value[, start, stop]) Return first index of value.
insert(self, index, object, /) Insert object before index.
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
pop(self[, index]) Remove and return item at index (default last).
remove(self, value, /) Remove first occurrence of value.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
reverse(self, /) Reverse IN PLACE.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
sort(self, /, *[, key, reverse]) Stable sort IN PLACE.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.

See get_parameters().