Data Augmentation Increases Accuracy of your model — But how ?

Sourav Kumar
Secure and Private AI Writing Challenge
6 min readJul 21, 2019
[Example of augmentation]

Suppose you are reading a numerical text and solved some questions, and then after few hours i ask some questions from it , but just reading the text won’t make you super genius so that you will be able to understand each and every type of question that could be asked in exams .

Then you decided to read that text again but now in slightly different manner , this time first you read more new questions and then came back to read the text and along with it finding the answer to those unseen questions.
This time your mind is more generalized over the data you are trying to train.
You also solved more and more questions but every one of them contained a new trick to apply as they quality over quantity is recommended for any exam.
And this time you preformed better 💪

Get yourself a treat !🎉

So, this makes sense.

Data augmentation is a strategy that enables practitioners to significantly increase the diversity of data available for training models, without actually collecting new data. Data augmentation techniques such as cropping, padding, and horizontal flipping are commonly used to train large neural networks. However, most approaches used in training neural networks only use basic types of augmentation. While neural network architectures have been investigated in depth, less focus has been put into discovering strong types of data augmentation and data augmentation policies that capture data invariances.

Now the questions is from where to bring the data if more data is not available ?

Don’t worry , we have a idea. Let’s understand this by a question :
Do you know the below monument ?

4 different Images of Eiffel Tower in a frame

You guessed it right — Eiffel Tower
Do you see any other monument in the frame below containing 4 “different images”- Oh not for you ! but for neural network it’s all different due to it’s size, color, zoom level, cropped, rotated, tilted etc….

It so happens that in a neural network , during training phase , if you feed data all similar to each other then , when your model when deployed for testing on real life data , gives poor accuracy and infact many incorrect predictions.

It happens because in real life dataset , one may encounter images or inputs similar to one above shown and then neural networks aren’t able to properly detect / classify the inputs / images if not properly trained on the different variety of data.

Let’s see visualization of different data augmentations.

Let’s see with augmented and without augmented dataset.

(Here we are going to use PyTorch)

Let’s visualize first Fashion-MNIST dataset (MNIST is too easy 😎) :

[FASHION-MNIST DATASET WITHOUT AUGMENTATION]

Let’s now augment dataset with different transformations.

[FASHION-MNIST DATASET WITHOUT AUGMENTATION]

Okay so, now you might be curious what are those transforms ?

RandomRotation(degrees) : Rotate the image by angle.   
degrees : Range of degrees to select from. If degrees is a number instead of sequence like (min, max), the range of degrees will be (-degrees, +degrees).
RandomResizedCrop(size) : Crop the given PIL Image to random size and aspect ratio.
size – expected output size of each edge
RandomHorizontalFlip(p) : Horizontally flip the given PIL Image randomly with a given probability p.Resize(size) : Resize the input PIL Image to the given size.size (sequence or int) – Desired output size. If size is a sequence like (h, w), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size)CenterCrop(size): Crops the given PIL Image at the center.

So , till now we have understood various transforms we can use for augmenting our dataset.

Let’s also visualize this on some RGB channels dataset.
Here , we take CIFAR-10 :

If we apply same transforms as before on this dataset :

[CIFAR-10 DATASET WITHOUT AUGMENTATION]
[CIFAR-10 DATASET WITH AUGMENTATION]

Let’s apply more transforms:

ColorJitter(brightness=0, contrast=0, saturation=0, hue=0) :
Randomly change the brightness, contrast and saturation of an image.
The parameters describe how much to jitter.

Results -

There are many more transforms available in PyTorch for populating the dataset with random new images for training to model which you can read here.

But it’s not that it increases the length of dataset as the transforms are applied on the images “on the fly” , that means only when the specific batch is preprocessed for sending to training loop. It’s more of dynamic than static.

“The epoch size does not change, you just get randomly transformed samples every epoch. So the concept of a static dataset becomes a bit more dynamic” — Soumith Chintala , creator of PyTorch

Tip 1: We can also create transforms for specific classes in a particular dataset but let’s keep that for another day !

Tip 2 : Also , Sometimes , applying heavy augmentations unnecessarily can result in poor accuracy.

Tip 3 : It is generally advisable to not use data augmentation in test set , as we don’t train over test set.

Lastly , i would cite a research paper’s results for accuracy in context to applying data augmentation over varied datasets :

[ http://cs231n.stanford.edu/reports/2017/pdfs/300.pdf]

— — — — — — — — — — — — — — — — — — — — — — — — — —

🏆 Bonus Tip : Dataset Augmentation is not only used in Vision Problems but also in NLP problems and applications because again you have to train the model and test it in real world so it should contain the nuances and actual language used by the humans while communicating between each other and so, for those interested more in checking out what all awesome augmentations are used for boosting model’s accuracy in NLP problems check this link for more awesome detailed explanation on this by @neptune.ai

— — — — — — — — — — — — — — — — — — — — — — — — — —

References :

🔗 https://pytorch.org/tutorials/beginner/data_loading_tutorial.html
🔗 http://cs231n.stanford.edu/reports/2017/pdfs/300.pdf

For more such awesome stories , you can subscribe or follow me.

Feel free to share your insights on the data augmentation in the comments section below.

Clap it! Share it! Follow Me !

— — — — — — — — — — — — — — — — — — — — — — — — — —

clap it

— — — — — — — — — — — — — — — — — — — — — — — — — —

--

--

Sourav Kumar
Secure and Private AI Writing Challenge

Deep Learning 💻| Machine Learning 📊| Full stack Web development 🌐| cosmos lover 👨‍🚀