Data Augmentation explained
text
Data augmentation for machine learning
In this post, we'll be discussing data augmentation and under what circumstances we may want to use it.
Data augmentation occurs when we create new data based on modifications of our existing data. Essentially, we're creating new, augmented data by making reasonable modifications to data in our training set.
For example, we could augment image data by flipping the images, either horizontally or vertically. We could rotate the images, zoom in or out, crop, or even vary the color of the images. All of these are common data augmentation techniques.
- Horizontal flip
- Vertical flip
- Rotation
- Zoom in
- Zoom out
- Cropping
- Color variations
Why would we want to do this, though? Why use data augmentation?
Why use data augmentation?
Well, we may just want or need to add more data to our training set. For example, say we have a relatively small amount of samples to include in our training set, and it's difficult to get more. Then we could create new data from our existing data set using data augmentation to create more samples.
Reducing overfitting
Additionally, we may want to use data augmentation to reduce overfitting. Recall, we mentioned this point in our post that covered overfitting.
If our model is overfitting, one technique to reduce it to add more data to the training set. Given the first point we just made a moment ago, we can easily create more data using data augmentation if we don't have access to additional data.
Also, in regards to overfitting, think about if we had a data set full of images of dogs, but most of the dogs were facing to the right.
If a model was trained on these images, it's reasonable to think that the model would believe that only these right-facing dogs were actually dogs. It may very well not classify left-facing dogs as actually being dogs when we deploy this model in the field or use it to predict on test images.
With this, producing new right-facing images of dogs by augmenting the original images of left-facing dogs would be a reasonable modification. We would do this by horizontally flipping the original images to produce new ones.
Now, some data augmentation techniques may not be appropriate to use on our given data set. Sticking with the dog example, we stated that horizontally flipping our dog images makes sense, however, it wouldn't necessarily be reasonable to modify our dog images by vertically flipping them.
In real world images of dogs, it's not really as likely that we'll be seeing many images of dogs flipped upside down on their heads or backs.
Wrapping up
Hopefully now you have an understanding for what data augmentation is and why it would make sense to use it. If you're interested in seeing how to do implement data augmentation in code using Keras, be sure to check out the Keras series where we implement data augmentation.
In that series, we show how to make 10
augmented images from a single original image of a dog by rotating the image, shifting the width and height, zooming, varying the color, and horizontally
flipping the image.
This is actually pretty simple to implement when we use Keras' ImageDataGenerator
class. You can find out all the necessary technical details for how this is done in
this post. I'll see ya in the
next one!
quiz
resources
updates
Committed by on