You are on page 1of 18

Deep Learning

What is Data Augmentation??


• Data augmentation is a technique of artificially increasing the training
set by creating modified copies of a dataset using existing data. It
includes making minor changes to the dataset or using deep learning
to generate new data points.
Augmented vs. Synthetic data
• Augmented data is driven from original data with some minor changes. In the case of image
augmentation, we make geometric and color space transformations (flipping, resizing, cropping,
brightness, contrast) to increase the size and diversity of the training set.

• Synthetic data is generated artificially without using the original dataset. It often uses DNNs
(Deep Neural Networks) and GANs (Generative Adversarial Networks) to generate synthetic data.

• Note: the augmentation techniques are not limited to images. You can augment audio, video,
text, and other types of data too.
When Should You Use Data
Augmentation?
1. To prevent models from overfitting.

2. The initial training set is too small.

3. To improve the model accuracy.


Image Augmentation
1. Geometric transformations: randomly flip, crop, rotate, stretch, and zoom images. You
need to be careful about applying multiple transformations on the same images, as
this can reduce model performance.

2. Color space transformations: randomly change RGB color channels, contrast, and
brightness.

3. Kernel filters: randomly change the sharpness or blurring of the image.

4. Random erasing: delete some part of the initial image.

5. Mixing images: blending and mixing multiple images.


Advanced Techniques
1. Generative adversarial networks (GANs): used to generate new
data points or images. It does not require existing data to generate
synthetic data.

2. Neural Style Transfer: a series of convolutional layers trained to


deconstruct images and separate context and style.
Image Rescaling and Resizing
Image Rescaling and Resizing
• This code resizes and rescales an image using the Keras library.
• First, a constant IMG_SIZE is defined with a value of 180.
• Then, a Sequential model is created using the keras.Sequential function.
• This model consists of two layers: Resizing and Rescaling.
• The Resizing layer resizes the input image to the specified IMG_SIZE value.
• The Rescaling layer scales the pixel values of the image to a range between
0 and 1 by dividing each pixel value by 255.
• The result variable is assigned the output of the resize_and_rescale model
when it is applied to the image variable.
• Finally, the result image is displayed using the plt.imshow function with
the plt.axis('off') function used to remove the axis labels.
Random Rotate and Flip
Random Rotate and Flip
• This code creates a data augmentation pipeline using the Keras Sequential API.
• The pipeline consists of two data augmentation layers: RandomFlip and
RandomRotation.
• The RandomFlip layer randomly flips the input image horizontally and/or vertically.
• The "horizontal_and_vertical" argument specifies that both types of flips are allowed.
• The RandomRotation layer randomly rotates the input image by a specified angle.
• In this case, the angle is set to 0.4 radians.
• The for loop iterates 6 times, each time applying the data augmentation pipeline to the
input image and displaying the augmented image using matplotlib.
• The plt.subplot function is used to create a grid of subplots, with 2 rows and 3 columns.
• The augmented image is normalized by dividing by 255 before being displayed.
OUTPUT of Rotation and Flipping
How to apply augmentation to the model
Flip Right and Left
Flip Right and Left
• This code defines a function called visualize that takes two arguments: original and augmented.
• The purpose of this function is to display two images side by side for comparison.
• The function creates a new figure using plt.figure().
• It then creates two subplots using plt.subplot(1,2,1) and plt.subplot(1,2,2).
• The 1,2 argument specifies that there will be one row and two columns of subplots, and the 1 and
2 arguments specify the position of each subplot.
• For each subplot, the function sets a title using plt.title() and displays an image using
plt.imshow().
• The original image is displayed in the first subplot, and the augmented image is displayed in the
second subplot.
• The plt.axis("off") command is used to remove the axis labels and ticks from the images.
• Overall, this function is useful for visualizing the effects of image augmentation techniques on an
original image.
OUTPUT Flip Right and Left
OUTPUT of Grayscale
OUTPUT Adjusting the brightness
OUTPUT of 90-degree Rotation

You might also like