You are on page 1of 23

Data Augmentation

Techniques :
Introduction

Presented By :
ABHAY GUPTA
(18MCS001)
Brief Overview Of Deep Neural Nets
Convolutional Neural Network (CNN)
Convolutional neural network (ConvNets or CNNs) is one of the main categories to do images
recognition, images classifications. Objects detections, recognition faces etc., are some of the areas
where CNNs are widely used.
Architecture Outline And Variants Of CNN
 Provide input image into convolution layer
 Choose parameters, apply filters with strides, padding if
requires. Perform convolution on the image and apply ReLU
activation to the matrix.
 Perform pooling to reduce dimensionality size
 Add as many convolutional layers until satisfied
 Flatten the output and feed into a fully connected layer (FC
Layer)
 Output the class using an activation function (Logistic
Regression with cost functions) and classifies images.

3
Architecture Outline And Variants Of CNN
 AlexNet

It contains 5 convolutional layers and 3 fully connected layers. Dropout is used instead of regularisation to deal
with overfitting. However the training time is doubled with the dropout rate of 0.5.

4
Challenges With State-Of-The-Art Deep Neural
Architectures
ImageNet Classification with Deep Convolutional Neural Networks, Krizhevsky A., 2012

ImageNet Large-Scale Visual Recognition Challenge (ILSVRC)


1.2 million training images, 50,000 validation images, and
150,000 testing images
Overfitting!!
Architecture of 5 convolutional + 3 fully connected = 60
million parameters
Challenges With State-Of-The-Art Deep Neural
Architectures
 When we train a machine learning model, what we’re really doing is
tuning its parameters such that it can map a particular input (say, an
image) to some output (a label).
 Your neural network is only as good as the data you feed it.

“ State of the art neural networks typically have parameters


in the order of millions ! ”

“How do we get more data, if we don’t have “more data”? ”

6
Intuition Behind Data Augmentation
 In the real world scenario, we may have a dataset of images taken
in a limited set of conditions. But, our target application may exist
in a variety of conditions, such as different orientation, location,
scale, brightness etc.
 We account for these situations by training our neural network
with additional synthetically modified data.
 It can help to increase the amount of relevant data in our
dataset.

7
Intuition Behind Data Augmentation

Suppose that we have a dataset, consisting of two brands of cars, as shown above. Let’s assume that all cars of brand A
are aligned exactly like the picture in the left (i.e. All cars are facing left) . Likewise, all cars of brand Bare aligned exactly
like the picture in the right (i.e. Facing right) .

Our Trained Model Label it


as Brand B with 95 %
accuracy !!
8
Image Data Augmentation
Various Geometric Transformations
 Flip
You can flip images horizontally and vertically. a vertical flip is
equivalent to rotating an image by 180 degrees and then
performing a horizontal flip.

9
Image Data Augmentation
 Rotation
One key thing to note about this operation is that image dimensions may not
be preserved after rotation. If your image is a square, rotating it at right
angles will preserve the image size. If it’s a rectangle, rotating it by 180
degrees would preserve the size. Rotating the image by finer angles will also
change the final image size.

10
Image Data Augmentation
Random Cropping

11
Image Data Augmentation
 Random erasing
Random erasing is another interesting Data Augmentation technique
developed by Zhong et al. Inspired by the mechanisms of dropout regularization, random
erasing can be seen as analogous to dropout except in the input data space rather than
embedded into the network architecture.

12
Image Data Augmentation : Photometric
Transformations

13
Image Data Augmentation : Photometric
Transformations Complex:

 Color jitter 1. Apply PCA to all [R, G, B]


Simple: pixels in training set
Randomly jitter contrast
2. Sample a “color offset” along
principal component
directions
• Add offset to all pixels of a
training image

14
Data Augmentation In Practice

“cat”
Load image
and label

Compute
loss

CNN

Transform image

15
Data Augmentation In Practice
Various Frameworks For Image Augmentation are –
Data Augmentation Using Tensorflow
The tf.data API of Tensorflow is a great way to build a pipeline for sending data
to the GPU.
Loading Dataset : The CIFAR-10 dataset (Canadian Institute For Advanced
Research) is a collection of images that are commonly used to train machine
learning and computer vision algorithms
import tensorflow as tf
tf.enable_eager_execution() (x_train, y_train), (x_test, y_test) =
tf.keras.datasets.cifar10.load_data()
dataset =
tf.data.Dataset.from_tensor_slices((x_train[0:8]/255).astype(np.float32))
16
Data Augmentation In Practice
 Implementing augmentations Using Tenserflow
Code Implementation For Flipping--
def flip(x: tf.Tensor) -> tf.Tensor:
"""Flip augmentation
Args: x: Image to flip
Returns:
Augmented image
"""
x = tf.image.random_flip_left_right(x)
x = tf.image.random_flip_up_down(x)
return x

17
Data Augmentation In Practice
 Keras Image Augmentation API
Keras provides the ImageDataGenerator class that defines the configuration
for image data preparation and augmentation.

from keras.preprocessing.image import ImageDataGenerator


datagen = ImageDataGenerator( rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')

18
Data Augmentation Using Deep Neural
Networks
Feature space augmentation –
The use of auto-encoders is especially useful for performing feature space
augmentations on data. Autoencoders work by having one half of the network,
the encoder, map images into low-dimensional vector representations such that
the other half of the network, the decoder, can reconstruct these vectors back
into the original image. This encoded representation is used for feature space
augmentation.

19
Data Augmentation Using Deep Neural
Networks
• GAN-based Data Augmentation –

Generative modeling refers to the practice of creating artificial instances from a


dataset such that they retain similar characteristics to the original set.

20
Current Trends In Data Augmentation
Techniques
 Various Deep Fake Apps and technologies are using
GAN and other adversarial networks for generating
almost real datasets
 StyleGAN is being implemented in many models and
under research for generating fake faces and non-existant
personalities
 Style Transfer learning is currently being used as potential
data augmentation techniques.

21
References
 ImageNet Classification with Deep Convolutional Neural
Networks by Alex Krizhevsky et al
 Arjovsky, M. and Bottou, L. (2017). Towards principled
methods for training Generative Adversarial Networks.
In Proceedings of the Fifth International Conference on
Learning Representations (ICLR).

22

You might also like