Data augmentation is the process of increasing the amount and diversity of data. We do not collect new data, rather we transform the already present data. I will be talking specifically about image data augmentation in this article.
So we will look at various ways to transform and augment the image data.
This article covers the following articles –
- Need for data augmentation
- Operations in data augmentation
- Data augmentation in Keras
- Data augmentation using Augmentor
1. Need for data augmentation
Data augmentation is an integral process in deep learning, as in deep learning we need large amounts of data and in some cases it is not feasible to collect thousands or millions of images, so data augmentation comes to the rescue.
It helps us to increase the size of the dataset and introduce variability in the dataset.
2. Operations in data augmentation
The most commonly used operations are-
- Changing the brightness level
Now we will look at all these operations in detail. I will also provide the code for data augmentation later in the article.
The original image that I will use for illustration
Rotation operation as the name suggests, just rotates the image by a certain specified degree.
In the example below, I specified the rotation degree as 40.
Shearing is also used to transform the orientation of the image.
The result of shearing operation looks like this –
Zooming operation allows us to either zoom in or zoom out.
The result looks like this –
Cropping allows us to crop the image or select a particular area from an image.
Flipping allows us to flip the orientation of the image. We can use horizontal or vertical flip.
You should use this feature carefully as there will be scenarios where this operation might not make much sense e.g. suppose you are designing a facial recognition system, then it is highly unlikely that a person will stand upside down in front of a camera, so you can avoid using the vertical flip operation.
Changing the brightness level
This feature helps us to combat illumination changes.You can encounter a scenario where most of your dataset comprises of images having a similar brightness level e.g. collecting the images of employees entering the office, by augmenting the images we make sure that our model is robust and is able to detect the person even in different surroundings.
3. Data augmentation in Keras
Keras is a high-level machine learning framework build on top of TensorFlow. I won’t go into the details of the working of Keras, rather I just want to introduce the concept of data augmentation in Keras.
We can perform data augmentation by using the ImageDataGenerator class.
It takes in various arguments like – rotation_range, brightness_range, shear_range, zoom_range etc.
Code : Python code implementing Data augmentation
The above code snippet allows you to generate 5 augmented images having different zoom, rotation, brightness etc.
4. Data augmentation using Augmentor
The above code snippet allows you to generate 5 augmented images based on the features defined above.
You can checkout the Augmentor github repository for more information.
- Python Data Types
- Exporting PDF Data using Python
- Python for Data Science
- Exploratory Data Analysis in Python | Set 2
- Python | Pandas Index.data
- Exploratory Data Analysis in Python
- Exploratory Data Analysis in Python | Set 1
- How to fetch data from MongoDB using Python?
- Python IDEs For Data Science
- Data analysis and Visualization with Python
- Data Classes in Python | An Introduction
- Data Classes in Python | Set 4 (Inheritance)
- Multidimensional data analysis in Python
- Data Analysis and Visualization with Python | Set 2
- How to update data in a Collection using Python?
- Data profiling in Pandas using Python
- SQL using Python | Set 3 (Handling large data)
- 10 Reasons Why You Should Choose Python For Big Data
- Python - Stock Data Visualisation
- Python | Pandas Series.data
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.