Image Augmentation using Keras

Posted By :Manish Kumar |31st July 2022

 

What is Image Augmentation?

 

Image augmentation is a technique of modifying the existing data to create some new data for the model training process. It is the process of taking images that are already in a training dataset and manipulating them to create many altered versions of the same image. This increases the number of training images available, but it can also expose our classifier to a wider range of lighting and coloring conditions, strengthening it.

 

When Should we use Image Augmentation?

 

The input that a user will provide when working on image categorization projects might vary in numerous ways, including angles, zoom, and steadiness while clicking the photo. As a result, we should teach our model to take practically any input and understand it. In these situations when you are working with deep learning you'll find yourself in peculiar circumstances when there is not much data to train your model and gathering training data can be both frustrating and time-consuming. In times like this, image augmentation comes to rescue you.

 

Advantages

 

  

>>We can observe that the deep learning model's performance improves as the number of data increases.

 

Every time, having a lot of data to feed the deep learning network is impossible. The issue with not having enough data is that the deep learning model may not be able to extract the patterns or functions from the data, which could affect how effectively it performs. This not only makes your model more resilient, but it also reduces overhead RAM! Let's take a closer look at how this class is useful for image augmentation.

 

Different Image Augmentation Techniques

  1. Image rotation
  2. Image shifting
  3. Image flipping
  4. Image noising 
  5. Image blurring
  6. Image Brightness
  7. zoom Image

 

Implementation

 

## Installing Requirements (Keras Library)

pip install keras

 

 

## Importing Dependencies 

from keras.preprocessing.image import ImageDataGenerator

 

 

## Here we are applying the rules to generate data like its rotation range or if you want images to get flip or not

gen = ImageDataGenerator(rotation_range=10, width_shift_range=0.1,

                        height_shift_range=0.1, shear_range=0.15, zoom_range=0.1,

                        channel_shift_range=10, horizontal_flip=False)

 

 

## Expand the dimension of the image array

image = np.expand_dims(cv2.imread(image_path), 0)

 

 

## Here we're applying the required image in the function

aug_iter = gen.flow(image)

 

 

## We've created 10 images from one single image and getting them using the 'next' keyword  in a for loop

aug_images = [next(aug_iter)[0].astype(np.uint8) for i in range(10)]

 

 

## Now you can see and save every image using their index

plt.imshow(aug_images[5])

 

 

 


About Author

Manish Kumar

Manish holds more than 1+ year of industry experience and is working as a Backend developer. He has sound understanding of the latest technologies and has worked on various AI and ML projects, demonstrating his versatility in software Development. He is proficient in several programming languages, including Core Python, and has experience working with databases and Apache. He has expertise in web development using frameworks such as Django and Flask and has contributed to various AWS services, including deployment. He has contributed to several client projects, including Wellsite Dashboard Project and I-infinity project, showcasing his ability to develop solutions that meet the unique needs of businesses and users.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us