augmentation_primitives#

Helper functions to perform augmentations on a PIL.Image.Image.

Augmentations that take an intensity value are normalized on a scale of 1-10, where 10 is the strongest and maximum value an augmentation function will accept.

Adapted from AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty.

composer.algorithms.utils.augmentation_primitives.AugmentationFn[source]#

The type annotation for describing an augmentation function.

Each augmentation takes a PIL.Image.Image and an intensity level in the range [0, 10], and returns an augmented image.

Type

(Image, float) -> PIL.Image.Image

composer.algorithms.utils.augmentation_primitives.augmentation_sets[source]#

The collection of all augmentations. This dictionary has the following entries:

  • augmentation_sets["safe"] contains augmentations that do not overlap with

    ImageNet-C/CIFAR10-C test sets.

  • augmentation_sets["original"] contains augmentations that use the original

    implementations of enhancing color, contrast, brightness, and sharpness.

  • augmentation_sets["all"] contains all augmentations.

Type

Dict[str, List[AugmentationFn]]

Functions

autocontrast

Autocontrast an image.

brightness

Enhance brightness on an image.

brightness_original

Enhance brightness on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

color

Enhance color on an image.

color_original

Enhance color on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

contrast

Enhance contrast on an image.

contrast_original

Enhance contrast on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

equalize

Equalize an image.

posterize

Posterize an image.

rotate

Rotate an image.

sharpness

Enhance sharpness on an image.

sharpness_original

Enhance sharpness on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

shear_x

Shear an image horizontally.

shear_y

Shear an image vertically.

solarize

Solarize an image.

translate_x

Shear an image horizontally.

translate_y

Shear an image vertically.

Attributes

composer.algorithms.utils.augmentation_primitives.autocontrast(pil_img, level=0.0)[source]#

Autocontrast an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity.

composer.algorithms.utils.augmentation_primitives.brightness(pil_img, level)[source]#

Enhance brightness on an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.brightness_original(pil_img, level)[source]#

Enhance brightness on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.color(pil_img, level)[source]#

Enhance color on an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.color_original(pil_img, level)[source]#

Enhance color on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.contrast(pil_img, level)[source]#

Enhance contrast on an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.contrast_original(pil_img, level)[source]#

Enhance contrast on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.equalize(pil_img, level)[source]#

Equalize an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity.

composer.algorithms.utils.augmentation_primitives.posterize(pil_img, level)[source]#

Posterize an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.rotate(pil_img, level)[source]#

Rotate an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.sharpness(pil_img, level)[source]#

Enhance sharpness on an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.sharpness_original(pil_img, level)[source]#

Enhance sharpness on an image, following the corruptions in the ImageNet-C/CIFAR10-C test sets.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.shear_x(pil_img, level)[source]#

Shear an image horizontally.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.shear_y(pil_img, level)[source]#

Shear an image vertically.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.solarize(pil_img, level)[source]#

Solarize an image.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.translate_x(pil_img, level)[source]#

Shear an image horizontally.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].

composer.algorithms.utils.augmentation_primitives.translate_y(pil_img, level)[source]#

Shear an image vertically.

Parameters
  • pil_img (Image) โ€“ The image.

  • level (float) โ€“ The intensity, which should be in [0, 10].