ANN-Unit 9 - Convolutionary Neural Networks
ANN-Unit 9 - Convolutionary Neural Networks
Applied Neural
Networks
Unit 9
Lecture Outline
▪ Coevolutionary Neural Networks
▪ Edge Detection
▪ Padding and Stride
▪ Pooling
▪ Residual Networks
▪ Transfer Learning
1
1/14/2024
CNN Motivation
64 x 64 x 3 = 12288
{
1 million
2
1/14/2024
Convolution Operation
-5 -4 0 8
1 0 -1 -10 -2 2 3
* 1 0 -1 = 0 -2 -4 -7
1 0 -1 -3 -2 -3 -16
3x3
Filter/
Kernel
3
1/14/2024
Convolution Operation
4
1/14/2024
10
5
1/14/2024
11
12
6
1/14/2024
Padding
* =
3x3 4x4
fxf
n-f+1 = 4
6x6
nxn
13
Padding
• Padding: artificially fill borders of image
• Usually: fill with 0s
• Useful to keep spatial dimension constant
across filters
• The size of the output of a padded image can
be extracted using
• n+2p-f+1 x n+2p-f+1
• Where p is the padding size (p = 1 for this case)
14
7
1/14/2024
15
Strided Convolution
• Strides: increment step size for the convolution operator
• Reduces the size of the output map
▪ If you convolve an n x n image with f x f filter with padding p and
stride s then the output image size will be
𝑛+2p−𝑓 𝑛+2p−𝑓
▪ +1 x + 1
s s
91 100 83
69 91 127
44 72 74
16
8
1/14/2024
17
…..
18
9
1/14/2024
The Filters
Edge
19
Multiple Filters
Horizontal Edge
Vertical Edge
20
10
1/14/2024
Multiple Filters
Horizontal Edge across RGB
n x n x nc * f x f x nc
…. …. =
n – f+1 x n – f+1 x n’c
21
22
11
1/14/2024
Dimensions of a CNN
23
Example of a ConvNet
𝑛 + 2p − 𝑓 𝑛 + 2p − 𝑓
+1 x +1
s s
24
12
1/14/2024
25
Hyperparameters
No parameters to learn!
26
13
1/14/2024
27
28
14
1/14/2024
29
30
15
1/14/2024
Usually, a layer
Example: Digit Recognition of 400 neurons
in between
400
60,000 Parameters
31
32
16
1/14/2024
Why CNNs?
33
34
17
1/14/2024
Usually, a layer
LeNet 5 of 400 neurons
in between
400
60,000 Parameters
35
36
18
1/14/2024
VGG-16
37
Residual Networks
𝒂 𝒍+𝟐 = 𝒈 𝐳 𝒍+𝟐 + 𝒂 𝒍
38
19
1/14/2024
Residual Networks
39
40
20
1/14/2024
1x1 Convolution
41
42
21
1/14/2024
Pre-Trained Models
and Transfer Learning
Training a CNN model on ImageNet
from scratch takes days or weeks.
Many models trained on ImageNet
and their weights are publicly
available!
43
Freeze
Train
Dr. Muhammad Usman Arif; Applied Neural Networks 1/14/2024 44
44
22