Data Augmentation using Augmentor
Short description of what are the mostly used technique available in Augmentor. Also implementing it in 5 images.
- Why Data Augmentation?
- Installiing Augmentor
- Initialising a pipeline
- Explanation of different Function in Augmentor
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.
!pip install Augmentor
import Augmentor
p = Augmentor.Pipeline("E:\dataAugmentation\imgs")
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()
p.rotate(probability=0.3, max_left_rotation=10, max_right_rotation=10)
p.rotate90(probability=0.3)
p.rotate270(probability=0.3)
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)
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.
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.
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.
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.
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.
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.
p.sample(100)
[OFFICIAL DOCUMENTATION] : https://augmentor.readthedocs.io/en/master/index.html