Module: tfm.vision.augment

Augmentation policies for enhanced image/video preprocessing.

AutoAugment Reference:

RandAugment Reference: https://arxiv.org/abs/1909.13719 RandomErasing Reference: https://arxiv.org/abs/1708.04896 MixupAndCutmix:

RandomErasing, Mixup and Cutmix are inspired by https://github.com/rwightman/pytorch-image-models

Classes

class AutoAugment: Applies the AutoAugment policy to images.

class ImageAugment: Image augmentation class for applying image distortions.

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

class RandAugment: Applies the RandAugment policy to images.

class RandomErasing: Applies RandomErasing to a single image.

Functions

autocontrast(...): Implements Autocontrast function from PIL using TF ops.

bbox_wrapper(...): Adds a bboxes function argument to func and returns unchanged bboxes.

blend(...): Blend image1 and image2 using 'factor'.

brightness(...): Equivalent of PIL Brightness.

color(...): Equivalent of PIL Color.

contrast(...): Equivalent of PIL Contrast.

cutout(...): Apply cutout (https://arxiv.org/abs/1708.04552) to image.

cutout_video(...): Apply cutout (https://arxiv.org/abs/1708.04552) to a video.

equalize(...): Implements Equalize function from PIL using TF ops.

from_4d(...): Converts a 4D image back to ndims rank.

gaussian_filter2d(...): Performs Gaussian blur on image(s).

gaussian_noise(...): Add Gaussian noise to image(s).

grayscale(...): Convert image to grayscale.

invert(...): Inverts the image pixels.

level_to_arg(...): Creates a dict mapping image operation names to their arguments.

posterize(...): Equivalent of PIL Posterize.

rotate(...): Rotates the image by degrees either clockwise or counterclockwise.

rotate_with_bboxes(...): Equivalent of PIL Rotate that rotates the image and bbox.

select_and_apply_random_policy(...): Select a random policy from policies and apply it to image.

sharpness(...): Implements Sharpness function from PIL using TF ops.

shear_with_bboxes(...): Applies Shear Transformation to the image and shifts the bboxes.

shear_x(...): Equivalent of PIL Shearing in X dimension.

shear_y(...): Equivalent of PIL Shearing in Y dimension.

solarize(...): Solarize the input image(s).

solarize_add(...): Additive solarize the input image(s).

to_4d(...): Converts an input Tensor to 4 dimensions.

transform(...): Transforms an image.

translate(...): Translates image(s) by provided vectors.

translate_bbox(...): Equivalent of PIL Translate in X/Y dimension that shifts image and bbox.

translate_x(...): Equivalent of PIL Translate in X dimension.

translate_y(...): Equivalent of PIL Translate in Y dimension.

translate_y_only_bboxes(...): Apply translate_y to each bbox in the image with probability prob.

unwrap(...): Unwraps an image produced by wrap.

wrap(...): Returns 'image' with an extra channel set to all 1s.

wrapped_rotate(...): Applies rotation with wrap/unwrap.

NAME_TO_FUNC

{
 'AutoContrast': <function autocontrast>,
 'Brightness': <function brightness>,
 'Color': <function color>,
 'Contrast': <function contrast>,
 'Cutout': <function cutout>,
 'Equalize': <function equalize>,
 'Gaussian_Noise': <function gaussian_noise>,
 'Grayscale': <function grayscale>,
 'Invert': <function invert>,
 'Posterize': <function posterize>,
 'Rotate': <function wrapped_rotate>,
 'Rotate_BBox': <function rotate_with_bboxes>,
 'Sharpness': <function sharpness>,
 'ShearX': <function shear_x>,
 'ShearX_BBox': <function <lambda>>,
 'ShearY': <function shear_y>,
 'ShearY_BBox': <function <lambda>>,
 'Solarize': <function solarize>,
 'SolarizeAdd': <function solarize_add>,
 'TranslateX': <function translate_x>,
 'TranslateX_BBox': <function <lambda>>,
 'TranslateY': <function translate_y>,
 'TranslateY_BBox': <function <lambda>>,
 'TranslateY_Only_BBoxes': <function translate_y_only_bboxes>
}

PROB_FUNCS

{
 'TranslateY_Only_BBoxes'
}

REPLACE_FUNCS

{
 'Cutout',
 'Rotate',
 'Rotate_BBox',
 'ShearX',
 'ShearX_BBox',
 'ShearY',
 'ShearY_BBox',
 'TranslateX',
 'TranslateX_BBox',
 'TranslateY',
 'TranslateY_BBox',
 'TranslateY_Only_BBoxes'
}

REQUIRE_BOXES_FUNCS

{
 'Rotate_BBox',
 'ShearX_BBox',
 'ShearY_BBox',
 'TranslateX_BBox',
 'TranslateY_BBox',
 'TranslateY_Only_BBoxes'
}