Professional Documents
Culture Documents
Janani Ravi
CO-FOUNDER, LOONYCORN
www.loonycorn.com
Narrow and wide convolution
Zero-padding and the feature map sizes
Overview for convolutional layers
Calculating feature map dimensions
Batch normalization of input images
Building and training a CNN for image
classification
Changing model hyperparameters
Convolutional Neural Networks
Two Kinds of Layers in CNNs
Convolution Pooling
Local receptive field Subsampling of inputs
Typical CNN Architecture
ReLU
ReLU
Convolutional Pooling Convolutional
ReLU
ReLU
Convolutional Pooling Convolutional
P(Y = 0)
Fully Connected
Fully Connected
P(Y = 1)
Prediction
SoftMax
ReLU
ReLU
CNN Layers
Feed-forward
Layers
P(Y = 9)
P(Y=0) P(Y=9)
…
x1 x0 x1
x0 x1 x0
x1 x0 x1
Convolution result
Narrow vs. Wide Convolution
0 0 0 0.2 0.2 0
Convolution
Matrix Result
Zero Padding
10 8
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0
0 0.2 0.8 0 0.3 0.6 0
0
0
0
8
10 0 0 0.3 0.8 0.7 0.8 0.9 0 0 0
x1 x0
x0
x1
x1 x0
0 0 0 0 0 0.2 0.8 0 0 0 x1 x0 x1
0 0 0 0 0 0.2 0.2 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Convolution
Matrix Result
Zero Padding
12
0 0 0 0 0 0 0 0 0 0 0 0
10
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0.2 0.8 0 0.3 0.6 0 0 0 0
10
12 0
0
0
0
0 0.2 0.9 0 0.3 0.8 0
0 0.3 0.8 0.7 0.8 0.9 0
0
0
0
0
0
0
x1 x0
x0
x1
x1 x0
0 0 0 0 0 0 0.2 0.8 0 0 0 0 x1 x0 x1
0 0 0 0 0 0 0.2 0.2 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Convolution
Matrix Result
Zero Padding
0 0 0 0 0 0
x1 x0 x1
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Stride Size
0 0 0 0 0 0
x1 x0 x1
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Horizontal stride of 1
Stride Size
0 0 0 0 0 0
x1 x0 x1
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Stride Size
0 0 0 0 0 0
0.2
x0
0.9x1 0x0 0.3 0.8 0
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Vertical stride of 1
Stride Size
0 0 0 0 0 0
0.2
x0
0.9x1 0x0 0.3 0.8 0
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
ML-based Classifier
Object Parts
Corners
Edges
Pixels
Error
Optimiser
Vanishing and Exploding Gradients
W
Initial value of loss
W
Initial value of loss
Non-saturating activation
Proper initialization
function
Non-saturating activation
Proper initialisation
function
“Normalize” inputs
- subtract mean
- divide by standard deviation
“Scale and shift” inputs
- scale = multiply by constant
- shift = add constant
Batch Normalization
Supported in PyTorch
Many other benefits
- allows much larger learn rate
- reduces overfitting
- speeds convergence of training
Choice of Activation Function
A Neural Network
W1
X1
X2 W2 Affine Activation
Wi Transformation Wx + b Function max(Wx+
…
b,0)
Xi
…
Wn
Xn
b
W1
X1
X2 W2 Affine Activation
Wi Transformation Wx + b Function max(Wx+
…
b,0)
Xi
…
Wn
Xn
b
W1
X1
X2 W2 Affine Activation
Wi Transformation Wx + b Function max(Wx+
…
b,0)
Xi
…
Wn
Xn
b
W1
X1
X2 W2 Affine Activation
Wi Transformation Wx + b Function max(Wx+
…
b,0)
Xi
…
Wn
Xn
b
0 0 0 0.2 0.2 0
Convolution
Matrix Result
Zero Padding
10 8
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0
0 0.2 0.8 0 0.3 0.6 0
0
0
0
8
10 0 0 0.3 0.8 0.7 0.8 0.9 0 0 0
x1 x0
x0
x1
x1 x0
0 0 0 0 0 0.2 0.8 0 0 0 x1 x0 x1
0 0 0 0 0 0.2 0.2 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Convolution
Matrix Result
W-K+2P
O = + 1
S
O = Output dimension
Height/width of output
W-K+2P
O = + 1
S
W = Input dimension
Height/width of input image
W-K+2P
O = + 1
S
K = Kernel size
Height/width of kernel
W-K+2P
O = + 1
S
S = Stride
How far the kernel advances in each step
Stride Size
0 0 0 0 0 0
x1 x0 x1
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Stride Size
0 0 0 0 0 0
x1 x0 x1
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Horizontal stride of 1
Stride Size
0 0 0 0 0 0
x1 x0 x1
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Stride Size
0 0 0 0 0 0
0.2
x0
0.9x1 0x0 0.3 0.8 0
0 0 0 0.2 0.8 0
0 0 0 0.2 0.2 0
Vertical stride of 1
W-K+2P
O = + 1
S