![]() |
VOOZH | about |
Data augmentation is a technique used to increase diversity of a dataset without actually collecting new data. It works by applying various transformations to the existing data to create new, modified versions of data that helps the model generalize better. In this article, we will learn more about data augmentation.
Data augmentation for images works by applying various transformations technique to the original images. These transformations are applied in a way that maintains the original label of the data while creating augmented data for training. Some of these transformations are:
Geometric transformations alter the spatial properties of an image. It include:
Color space augmentations modify the color properties of an image. These include:
Kernel filters apply convolutional operations to enhance or suppress specific features in the image. It includes:
Random erasing involves randomly masking out a rectangular region of the image. This helps the model become invariant to occlusions and improves its ability to handle missing parts of objects.
In this multiple augmentation techniques are combined to create more varied training data. For example an image might be rotated, flipped and then have its brightness adjusted in a single augmentation pipeline.
Below is the step by step implementation of data augmentation:
Import the necessary libraries like numpy, matplotlib and tenserflow.
Create an instance of ImageDataGenerator with specified augmentation parameters such as rotation, width shift, height shift, shear, zoom and horizontal flip.
We will load an image from the CIFAR-10 dataset to use as an example for augmentation and display the original image using matplotlib.
Output:
Here we will reshape the image to include a batch dimension which is required by the flow method of ImageDataGenerator.
We will use the flow method to generate batches of augmented images. We will specify number of augmented images we want i.e 4 in this case.
We will display the generated augmented images in a matrix format using matplotlib subplots.
Output:
We can see that we get 4 augmented images of our original image. It is used for:
Several tools and libraries provide image data augmentation:
tf.image module provides functions for image transformations.ImageDataGenerator class for real-time data augmentation.torchvision.transforms module includes a wide range of augmentation techniques.Data augmentation is a technique for expanding and diversifying datasets particularly in image processing. By applying various transformations to existing data we can create new training examples that help improve model generalization, reduce overfitting and enhance robustness.