Lecture 2
Lecture 2
CNN Concepts
By: Dr. Eman Ahmed
Contents
• Intro to image processing.
• Sharpening (Edge Detection) Filters
• What is Stride?
• What is Padding? Why?
• Intro to CNN
What is image?
Image
10 110 1010 0 0 0 1 0 -1 0 30 30 0
0 0 30 30 0
1 0 -1
10 110 1100 0 0 0
0 1 0 -1
110 110 1010 0 0 0
0 0
110 110 1010 0 0 0
0 0
110 110 1010 0 0 0
0 0
110 101 1010 0 0 0
0 0
Horizontal Edge Detection
10 10 10 10 10 10
1 1 1 0 0 0 0
10 10 10 10 10 10 0 0 0 30 30 30 30
30 30 30 30
10 10 10 10 10 10 -1 -1 -1
0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Output Image Dimension
• n: original image dimension
• f: filter original dimension
• Output image dimension = (n-f+1)x(n-f+1)
Vertical Edge Detection
1 0 -1
1 0 -1
1 0 -1
2 1 0 8 9 4
4 0 5 5 2 6
W1 W2 W3
4 4 6 7 1 8
6 5 8 3 0 4 * W4 W5 W6
=
5 8 5 0 0 0
W7 W8 W9
4 6 8 0 8 7
What is Padding?
• Extending image size by adding rows and columns of zeros.
• When padding (P=1):
• One row is added up and down
• One column is added left and right.
• So, when P = 1 , number of rows increases by 2 and number of columns
increases by 2.
• When P = 2:
• Number of rows increases by 4 and number of columns increases by 4.
Why Padding?
• Shrinking the size of image after convolution (After few convolution,
the image will vanish).
• Edge pixels are not used much in the calculations.
Output Image Dimension With Padding
•
Strides
• The amount of shifting the filter.
• By default, stride = 1 meaning shifting one pixel.
•
Classical Pattern Recognition Flow
CNNs Weights of Filters are the features and are Any classifier such
trained by a neural network called as SVM can be
Convolutional Neural Networks (CNNs) used to classify the
image using the
extracted features.
Convolution over volumes
• Colored image has 3 matrices (R,G,B), how can we apply filter to it?
• The filter must have 3 dimensions, one applies to R, one applies to G,
and one applies to B.
• But, the output of the filter must have one dimension, how?
• For each pixel, the 3 values obtained by the filter are added resulting
in one value.
Multiple Filters
Convolutional Layer
• So , each filter can represent a neuron in the classical neural network.
• Number of filters = Number of Neurons in the hidden layer.
• A sequence of convolutional layers act as a sequence of hidden layers.
• Deeper hidden layers learn complex features. For example, the first
filters learn simple edges, the next ones can learn a combination of
these edges forming a shape, the next ones are able to learn more
complex shapes, …. Etc.
Notations
•
CNN Layers
• Feature Extraction
• Convolution
• Pooling (Feature Selection)
• Classification
• Fully connected
• Softmax (SVM)
Resources
• Andrew Ng: Deep Learning course on Coursera
• Andrew Ng: Convolutional Neural Networks Course on Coursera
• https://medium.com/swlh/convolutional-neural-networks-part-3-con
volutions-over-volume-and-the-convnet-layer-91fb7c08e28b
Thanks