Lecture 2 - CNN and Overfitting
Lecture 2 - CNN and Overfitting
Deep Learning
Lecture 2:
Convolutional Neural
Networks & Overfitting
Topics
1. Introduction to Convolutional Neural
Networks (CNN)
4. Handling Overfitting
Official (Closed) - Non Sensitive
1. Introduction to CNN
Official (Closed) - Non Sensitive
1. Introduction to CNN
https://www.youtube.com/watch?v=Gu0MkmynWkw
Official (Closed) - Non Sensitive
1. Introduction to CNN
The MNIST classification problem using CNN
Convolution
operation
Max-pooling
operation
Official (Closed) - Non Sensitive
1st Layer
Official (Closed) - Non Sensitive
Filter
weight
0 1 2
2 2 0
0 1 2
Source:
https://towardsdatascience.com/intuitively-understanding-convolutions-for-deep-learning-1f6f42faee1
Official (Closed) - Non Sensitive
0 1 2
2 2 0
0 1 2
Source:
https://towardsdatascience.com/intuitively-understanding-convolutions-for-deep-learning-1f6f42faee1
Official (Closed) - Non Sensitive
Output (5, 5, 1)
Source:
https://towardsdatascience.com/intuitively-understanding-convolutions-for-deep-learning-1f6f42faee1
Official (Closed) - Non Sensitive
Output (2, 2, 1)
Source:
https://towardsdatascience.com/intuitively-understanding-convolutions-for-deep-learning-1f6f42faee1
Official (Closed) - Non Sensitive
(-2)+(-1)+(0)+0=-3
Input width =5
Padding = 1
Strides = 2
Filter Size
is 3 x 3
Source:
https://computersciencewiki.org/index.php/Max-pooling_/_Pooling
Official (Closed) - Non Sensitive
Datasets
1. Kaggle 2013 competition
Original: 25,000 images (12,500 dogs and 12,500
cats)
A Small Set:
• Training: 2,000 images (1,000 dogs and 1,000 cats)
• Validation: 1,000 images (500 dogs and 500 cats)
• Testing: 1,000 images (500 dogs and 500 cats)
2. Data Preprocessing ImageDataGenerator
in Keras
Read the picture files
Decode the JPEG content to RGB grids of pixels
Convert these into floating-point tensors
Rescale the pixels values (0-255) to [0,1] interval
Official (Closed) - Non Sensitive
3 (RGB) 150
3x3x32
150
148
32
3x3x64
148
74 32
74
64
72
72 64
36
3x3x128
36
128
34
34
Official (Closed) - Non Sensitive
128
128
34
34
17
128
17
3x3x128
15
128
15
7
7
Official (Closed) - Non Sensitive
128
7
7
7*7*128=6272
[0.1,0.234,0.521,0.2,…,0.454,0.442,0.984]
512 nodes ……
Output
(Sigmoid)
Official (Closed) - Non Sensitive
3 (RGB) 150
3x3x32
150
148
32
148
128
7
7
7*7*128=6272
[0.1,0.234,0.521,0.2,…,0.454,0.442,0.984]
512 nodes ……
Output
(Sigmoid)
Official (Closed) - Non Sensitive
4. Handling Overfitting
Official (Closed) - Non Sensitive
Underfitting
• The lower the error on training data, the lower the
error on testing data still progress to be made
Overfitting
• Generalization stops improving:
Training error keeps decreasing
Validation / Testing error starts to increase
• Model beginning to learn patterns overly-specific to
training data only
Official (Closed) - Non Sensitive
(Testing)
Optimizing Regularizing
Official (Closed) - Non Sensitive
3.Adding dropout
• High Capacity
Good at fitting to the training data
• Limited Capacity
Good at generalizing to unseen data (prediction)
• Ridge
Implemented in Keras
In layers function, add in an argument to configure
weight regularizer
Official (Closed) - Non Sensitive
Original Image
(150 x 150 pixels)
Official (Closed) - Non Sensitive
148
32
These new images 2000 images
are not saved 148
anywhere. Epoch 2
128
Output Validates
Epoch 5 (Sigmoid)
2000 images
Official (Closed) - Non Sensitive
Wrapping Up
CNN are the best type of machine-
learning models for computer-
vision tasks
Further Reading
Demystifying Convolutional Neural Networks
• https://towardsdatascience.com/demystifying-conv
olutional-neural-networks-384785791596
Q&A
Official (Closed) - Non Sensitive
References
Books:
Online Resources: