Why Data Augmentation?

Limited data is a major obstacle in applying deep learning models like convolutional neural networks. Often, imbalanced classes can be an additional hindrance; while there may be sufficient data for some classes, equally important, but undersampled classes will suffer from poor class-specific accuracy.

Machine learning applications especially in deep learning domain continue to diversify and increase rapidly. Data augmentation techniques may be a good tool against challenges which artificial intelligence world faces.

Data augmentation is useful to improve performance and outcomes of machine learning models by forming new and different examples to train datasets. If dataset in a machine learning model is rich and sufficient, the model performs better and more accurate.

Installiing Augmentor

!pip install Augmentor
Requirement already satisfied: Augmentor in c:\users\dell\anaconda3\envs\augmenttor\lib\site-packages (0.2.9)
Requirement already satisfied: tqdm>=4.9.0 in c:\users\dell\anaconda3\envs\augmenttor\lib\site-packages (from Augmentor) (4.62.3)
Requirement already satisfied: future>=0.16.0 in c:\users\dell\anaconda3\envs\augmenttor\lib\site-packages (from Augmentor) (0.18.2)
Requirement already satisfied: Pillow>=5.2.0 in c:\users\dell\anaconda3\envs\augmenttor\lib\site-packages (from Augmentor) (8.4.0)
Requirement already satisfied: numpy>=1.11.0 in c:\users\dell\anaconda3\envs\augmenttor\lib\site-packages (from Augmentor) (1.19.5)
Requirement already satisfied: colorama in c:\users\dell\anaconda3\envs\augmenttor\lib\site-packages (from tqdm>=4.9.0->Augmentor) (0.4.4)

Initialising a pipeline

import Augmentor
p = Augmentor.Pipeline("E:\dataAugmentation\imgs")
Initialised with 5 image(s) found.
Output directory set to E:\dataAugmentation\imgs\output.

Explanation of different Function in Augmentor

Rotating

Rotating can be performed in a number of ways. When rotating by modulo 90, the image is simply rotated and saved. To rotate by arbitrary degrees, then a crop is taken from the centre of the newly rotated image.

Rotate functions that are available are:- rotate()- rotate90()

  • rotate180()
  • rotate270()
  • rotate_random_90()

Abouth the probabilty argument

  • probability – A value between 0 and 1 representing the probability that the operation should be performed.
p.rotate(probability=0.3, max_left_rotation=10, max_right_rotation=10)
p.rotate90(probability=0.3)
p.rotate270(probability=0.3)

Flipping

Flip (mirror) the image along its horizontal axis, i.e. from left to right.

p.flip_left_right(probability=0.3)

Flip (mirror) the image along its vertical axis, i.e. from top to bottom.

p.flip_top_bottom(probability=0.3)

Cropping

Crop a random area of an image, based on the percentage area to be returned.

This function crops a random area from an image, based on the area you specify using percentage_area.

p.crop_random(probability=.1, percentage_area=0.5)
  • percentage_area (Float) – The area, as a percentage of the current image’s area, to crop.
  • randomise_percentage_area (Boolean) – If True, will use percentage_area as an upper bound and randomise the crop from between 0 and percentage_area.

Resizing

Resize an image according to a set of dimensions specified by the user in pixels.

p.resize(probability=0.1, width=100, height=100)
  • width (Integer) – The new width that the image should be resized to.
  • height (Integer) – The new height that the image should be resized to.

Random Brightness

Random change brightness of an image.

p.random_brightness(probability = 0.5, min_factor=0.4, max_factor=0.9)
  • min_factor – The value between 0.0 and max_factor that define the minimum adjustment of image brightness. The value 0.0 gives a black image, value 1.0 gives the original image, value bigger than 1.0 gives more bright image.

  • max_factor – A value should be bigger than min_factor that define the maximum adjustment of image brightness. The value 0.0 gives a black image, value 1.0 gives the original image, value bigger than 1.0 gives more bright image.

Random Color

Random change saturation of an image.

p.random_color(probability=0.5, min_factor=0.4, max_factor=0.9)
  • min_factor – The value between 0.0 and max_factor that define the minimum adjustment of image saturation. The value 0.0 gives a black and white image, value 1.0 gives the original image.
  • max_factor – A value should be bigger than min_factor that define the maximum adjustment of image saturation. The value 0.0 gives a black and white image, value 1.0 gives the original image.

Random Contrast

Random change image contrast.

p.random_contrast(probability=0.5, min_factor=0.9, max_factor=1.4)
  • min_factor – The value between 0.0 and max_factor that define the minimum adjustment of image contrast. The value 0.0 gives s solid grey image, value 1.0 gives the original image.
  • max_factor – A value should be bigger than min_factor that define the maximum adjustment of image contrast. The value 0.0 gives s solid grey image, value 1.0 gives the original image.

Random distortion

Random distortions allow you to make distortions to an image while maintaining the image’s aspect ratio.

This function performs a randomised, elastic distortion controlled by the parameters specified. The grid width and height controls how fine the distortions are. Smaller sizes will result in larger, more pronounced, and less granular distortions. Larger numbers will result in finer, more granular distortions. The magnitude of the distortions can be controlled using magnitude.

p.random_distortion(probability=0.5, grid_width=7, grid_height=8, magnitude=9)
  • grid_width (Integer) – The number of rectangles in the grid’s horizontal axis.
  • grid_height (Integer) – The number of rectangles in the grid’s vertical axis.
  • magnitude (Integer) – The magnitude of the distortions.

Random Erasing

This operation performs a Random Erasing operation, as described in https://arxiv.org/abs/1708.04896 by Zhong et al.

Its purpose is to make models robust to occlusion, by randomly replacing rectangular regions with random pixel values.

For greyscale images the random pixels values will also be greyscale, and for RGB images the random pixels values will be in RGB.

p.random_erasing(probability=0.5, rectangle_area=0.2)
  • rectangle_area – The percentage area of the image to occlude with the random rectangle, between 0.1 and 1.

Zooming

Zoom in to an image, while maintaining its size. The amount by which the image is zoomed is a randomly chosen value between min_factor and max_factor.

p.zoom(probability=0.7, min_factor=1.1, max_factor=1.5)
  • min_factor (Float) – The minimum factor by which to zoom the image.
  • max_factor (Float) – The maximum factor by which to zoom the image.

Output

p.sample(100)
Processing <PIL.Image.Image image mode=RGB size=1920x1280 at 0x11F10768128>: 100%|█| 100/100 [00:14<00:00,  7.13 Sample

EXPLORE MORE OPERATIONS