When a deep learning model learns the training data too well, it ends up failing on new data it hasn't seen before. This is called overfitting, and it's a huge problem, especially with small datasets.
Data augmentation is a powerful trick that helps fix overfitting. It works by creating new training data from your existing images by applying random transformations like:
- Flipping (
layers.RandomFlip) - Rotating (
layers.RandomRotation) - Zooming (
layers.RandomZoom)
This makes your model more robust and able to generalize better to unseen images.
This notebook shows a simple step-by-step example using TensorFlow and Keras.
- The Dataset: We start with the
flower_photosdataset, which is a perfect example for demonstrating overfitting. - The Base Model: We first train a simple Convolutional Neural Network (CNN) without any data augmentation to establish a baseline.
- The Augmented Model: We then add a data augmentation layer to the model and re-train it.
By training on an augmented dataset, the model's performance on new data improves significantly.
- Baseline Model (without augmentation): Our initial model achieved an accuracy of approximately 71.3% on the validation set.
- Augmented Model (with augmentation): The augmented model is expected to show a substantial increase in accuracy, proving that data augmentation successfully helps the model generalize better and reduces overfitting.
To get started, simply open the Data augmentation solve Overfitting.ipynb notebook in a Jupyter environment and run all the cells. The notebook will handle all the data downloads and model training for you.
You'll see the results for yourself in the output!