Data preparation is required when working with neural network and deep learning models. Increasingly data augmentation is also required on more complex object recognition tasks.
Data augmentation means to increase the amount of data. In, other words, having a larger dataset means a more robust model. But acquiring more data cannot always be as easy and there may be a problem of storing them and feeding it to model.
To mitigate this problem, we can manually increase the data by doing some changes or we can make use of one of Keras image preprocessing class that can do this in just a few lines of codes.
In this post you we’ll see how to use data preparation and data augmentation with your image datasets when developing and evaluating deep learning models in Python with Keras.
About the image augmentation API provide by Keras and how to use it with your models.
- How to perform feature standardization.
- How to perform ZCA whitening of your images.
- How to augment data with random rotations, shifts and flips.
- How to save augmented image data to disk.
Keras Image Augmentation API: ImageDataGenerator:
It generates batches of augmented data from the original batch. It takes the images, applies some random transformation on it, and produces a new batch for training. Note: One thing to note here that ImageDataGenerator does not return the original images instead it just returns batches of augmented data which is a result of some transformation done on original data.
- Loading Dataset
We will use MNIST handwritten digit recognition for data augmentation. Executing below code will load MNIST dataset from keras.datasets
- Standardizing Features
The pixel standardization is supported at two levels: either per-image (called sample-wise) or per-dataset (called feature-wise). Specifically, the mean and/or mean and standard deviation statistics required to standardize pixel values can be calculated from the pixel values in each image only (sample-wise) or across the entire training dataset (feature-wise). You can perform feature standardization by setting the featurewise_center and featurewise_std_normalization arguments on the ImageDataGenerator class
- ZCA Whitening
A whitening transform of an image is a linear algebra operation that reduces the redundancy in the matrix of pixel images. Typically, image whitening is performed using the Principal Component Analysis (PCA) technique. More recently, an alternative called ZCA shows better results and results in transformed images that keeps all of the original dimensions and unlike PCA, resulting transformed images still look like their originals.
- Random Rotations
ou can train your model to better handle rotations of images by artificially and randomly rotating images from your dataset during training. The example below creates random rotations of the MNIST digits up to 90 degrees by setting the rotation_range argument.
- Random Shifts
Objects in your images may not be centered in the frame. They may be off-center in a variety of different ways. You can train your deep learning network to expect and currently handle off-center objects by artificially creating shifted versions of your training data. Keras supports separate horizontal and vertical random shifting of training data by the width_shift_range and height_shift_range arguments.
- Random Flips
Another augmentation to your image data that can improve performance on large and complex problems is to create random flips of images in your training data. Keras supports random flipping along both the vertical and horizontal axes using the vertical_flip and horizontal_flip arguments.
- Save Augmented Images to file
depend on these articles link link