SlideShare a Scribd company logo
M&S
Convolutional Neural
Network from Theory
to Code
Seongwon Hwang
M&S
Preliminaries
M&S
Tensor :
(Index Notation)
ky
kl
ijy
ijklA
kj
a
ijA iA
ki
jjB
M&S
Order (Rank)
M&S
Range
𝑎 𝑏
𝑐 𝑑
𝑎 𝑏 𝑐
𝑑 𝑒 𝑓
𝑔 ℎ 𝑖
𝑎 𝑏
𝑒 𝑓
𝑐 𝑑
𝑔 ℎ
𝑖 𝑗
𝑚 𝑛
𝑘 𝑙
𝑜 𝑝
𝐴𝑖𝑗
i = 2, j = 2
i = 3, j = 3 i = 4, j = 4
𝑎 𝑏
𝑐 𝑑
𝑒 𝑓
i = 3, j = 2
M&S
Free index : unrepeated index
𝑦1 = 𝑎11 𝑥1+𝑎12 𝑥2
𝑦2 = 𝑎21 𝑥1+𝑎22 𝑥2
𝑦 𝑘 = 𝑎 𝑘1 𝑥1+𝑎 𝑘2 𝑥2, k = 1,2


2
1i
ikik xay
),( 21 yyy 
M&S
Dummy index : repeated index
1,2kixay ikik  ,
Free index Dummy index


2
1i
ikik xay
𝑦1 = 𝑎11 𝑥1+𝑎12 𝑥2
𝑦2 = 𝑎21 𝑥1+𝑎22 𝑥2
M&S
Example
iji BA jj BABA 2211 =
212111,1 BABAj 
222121,2 BABAj 
),( 222121212111 BABABABA iji BA =
i, j = 1,2
M&S
Example
ijjA 332211 iii AAA 
),,( 333322311233222211133122111 AAAAAAAAA 
133122111,1 AAAi 
233222211,2 AAAi 
333322311,3 AAAi 
=
i, j = 1,2,3
M&S
e-Permutation
ijke
M&S
Example – Determinant
bcad
dc
ba
aa
aa
A  detdetdet
2221
1211
bcad
aaaa
aaeaaeaaeaae
aae jiij




00 21122211
221222211221221112211111
21
M&S
Example – Determinant
)(...det 21... matrixNNaaaeA Nkjikij 
M&S
Kronecker delta
M&S
Derivatives
kjjkjj
xx
y
y
x
y
y






2
,, ,
1,2,3jφ
x
φ
z
φ
y
φ
x
φ
φgrad jj










 ),,( ,
Example – Gradient
M&S
CNN Tensor notation in Theano
- Input Images -
4D tensor
1D tensor
[number of feature maps at layer m, number of feature maps at layer m-1,
filter height, filter width]
ij
klx
op
qrW
mb
[ i, j, k, l ] =
[ o, p, q, r ] =
[ m ] =
- Weight -
- Bias -
[n’th feature map number]
[mini-batch size, number of input feature
maps, image height, image width]
M&S
Convolutional Neural
Network
Theory I
M&S
Convolution?





daatwax
twxty
)()(
))(()(




a
anwaxny ][][][
- Continuous Variables -
- Discrete Variables -
M&S
Convolution?




a
anwaxny ][][][
- Discrete Variables -
][][ awax ][][ awax 
)]([][ nawax 
Y-axis transformation
M&S
Y축
X축
Convolution?
X축
X축
M&S
Cross-Correlation?




a
nawaxnwxny ][][])[(][
- Discrete Variables (In real number) -
][][ awax ][][ nawax n step move
★
M&S
Convolution VS. Cross-Correlation
Cross-CorrelationConvolution
M&S
Cross-Correlation in 2D
Output (y) Kernel (w) Input (x)
 






n m
nmwjnimx
jiwxjiy
],[],[
],)[(],[
M&S
Intuition for Cross-Correlation
wx
★
M&S
wx
★
Intuition for Cross-Correlation
M&S
wx
★
Intuition for Cross-Correlation
M&S
wx
★
Intuition for Cross-Correlation
M&S
wx
★
Intuition for Cross-Correlation
Input
)( mapFreature
neuronHidden
fieldrecptiveLocal
filterorkernel
M&S
Convolutional Neural
Network
Theory II
M&S
CNN overall procedures
Input Image Convolutional Layer Pooling MLP Softmax Output
M&S
CNN overall procedures
Input Image
Convolutional
Layer
Pooling
MLP
Softmax Output
M&S
Input Image
Input Image
1D - Input neurons
2D - Input neurons
M&S
Convolutional Layer
Input Image
Convolutional
Layer
Input neurons
Hidden neuron
M&S
Traditional Neural Network
Input layer Hidden layer Output layer
M&S
CNN - Sparse Connectivity
Input layer Hidden layer
(Feature map)
Output layer
M&S
CNN – Dimension shrinkage ( + Pooling)
Input layer Output layerHidden layer
(Feature map)
M&S
Cross-Correlation Input (or Hidden) layer with weight
Input layer Output layer
1W
2W
3W
'3W
'2W
'1W
Hidden layer
(Feature map)(Receptive field)
M&S
Shared Weight representation
Input layer Output layer
1W
2W
3W
'3W
'2W
'1W
Hidden layer
(Feature map)
M&S
Shared Weight representation
Input layer Output layer
1W
2W
3W
'3W
'2W
'1W
Hidden layer
(Feature map)
M&S
Shared Weight representation
Input layer Output layer
1W
2W
3W
'3W
'2W
'1W
Hidden layer
(Feature map)
M&S
Shared Weight representation
Input layer Output layer
1W
2W
3W
'3W
'2W
'1W
Hidden layer
(Feature map)
M&S
Shared Weight representation
Input layer Output layer
1W
2W
3W
'3W
'2W
'1W
Hidden layer
(Feature map)
M&S
Shared Weight representation
Input layer Output layer
1W
2W
3W
'3W
'2W
'1W
Hidden layer
(Feature map)
M&S
Multiple Feature maps
Input Image
Convolutional
Layer
Input neurons
First hidden layer
M&S
Max Pooling
Input Image
Convolutional
Layer
Pooling
Max pooling with
2x2 filters and stride 2
M&S
Why pooling?
Input Image
Convolutional
Layer
Pooling
1. Low computation 2. Translation invariance
3. Transformation invariance
4. Scaling invariance
M&S
Several types of Pooling
Input Image
Convolutional
Layer
Pooling
M&S
Transform data dimension before MLP
Input Image
Convolutional
Layer
Pooling
MLP
1D - Output neurons
2D - Output neurons
M&S
Multilayer Perceptron (MLP)
Input Image
Convolutional
Layer
Pooling
MLP
Input layer Hidden layer 1 Hidden layer 2
M&S
Softmax Output
Input Image
Convolutional
Layer
Pooling
MLP
Softmax Output
Hidden layer 2 Output layer
M&S
Several types of CNN
M&S
Intuition for CNN
Input Image
Convolutional
Layer
Pooling
MLP
Softmax Output
M&S
Convolutional Neural
Network
Code in Theono
M&S
CNN overall procedures
Input Image
Convolutional
Layer
Pooling
MLP
Softmax Output
M&S
Input Image
Input Image
- Input Images -
4D tensor
[mini-batch size, number of input feature
maps, image height, image width]ij
klx
5
...
28
28
500
7
[ i, j, k, l ] =
Mini batch 1
5
...
28
28
500
8
Mini batch 100
. . .
50,000 images
in the training data
M&S
Weight tensor
Input Image
Convolutional
Layer
4D tensor
[number of feature maps at layer m, number of feature maps at layer m-1,
filter height, filter width]
op
qrW [ o, p, q, r ] =
- Weight -
M&S
Exercise for Input and Weight tensor
11
11x
11
11W
Input layer
Convolutional layer 1 Convolutional layer 2
[ 1, 1, 1, 1 ]
[ 1, 1, 1, 1 ]
M&S
Code for Convolutional Layer
28
28
8
def evaluate_lenet5(learning_rate=0.1,
n_epochs=2, dataset=‘minist.pkl.gz’,
nkerns=[20, 50], batch_size=500):
LeNetConvPoolLayer
image_shape=(batch_size, 1, 28, 28)
filter_shape=(nkerns[0], 1, 5, 5)
poolsize=(2, 2)
image_shape=(batch_size, nkerns[0], 12, 12)
filter_shape=(nkerns[1], nkerns[0], 5, 5)
poolsize=(2, 2)
Layer0 – Convolutional layer 1
Layer1 – Convolutional layer 2
5
5
20
24
24
20
5
5
12
12
8
8
4
4
20 50 50 50
28 – 5 + 1 = 24
Convolution
24 / 2 = 12
Pooling
12 – 5 + 1 = 8
Convolution
8 / 2 = 4
Pooling
Class
M&S
Zero-Padding Input layer Output layerHidden layer
(Feature map)
Input Image
Convolutional
Layer
Pooling
M&S
Zero-Padding Input layer Output layerHidden layer
(Feature map)
0
0
M&S
Zero-Padding Input layer Output layerHidden layer
(Feature map)
0
0
M&S
Zero-Padding Input layer Output layerHidden layer
(Feature map)
0
0
M&S
Zero-Padding Input layer Output layerHidden layer
(Feature map)
0
0
M&S
Zero-Padding Input layer Output layerHidden layer
(Feature map)
0
0
0
0
M&S
Zero-Padding Input layer Output layerHidden layer
(Feature map)
0
0
0
0
M&S
Zero-Padding
0
0
M&S
Zero-Padding
0
0
M&S
Zero-Padding
0
0
M&S
Zero-Padding
0
0
0
0
M&S
Zero-Padding
0
0
0
0
M&S
Zero-Padding
0
0
0
0
M&S
Zero-Padding
No zero-padding Zero-padding 1 Zero-padding 2
Dimension Reduction Dimension Equality Dimension Increase
Zero-
padding in
Theano
Default in
Theano
M&S
Code for Zero-Padding setting in Theano Library
conv.py (In Library File)
def conv2d(input, filters, image_shape=None, filter_shape=None,
border_mode=‘valid’, subsample=(1, 1), **kargs):
‘valid’ ‘full’
We should modify dimension changes in code by ourselves!
Image_shape + filter_shape – 1Image_shape - filter_shape + 1
28 + 5 – 1 = 3228 - 5 + 1 = 24
M&S
1. Border in Pooling
No problem in Border Ingore_border = False Ingore_border = True
M&S
1. Border in Pooling (Code)
No problem in Border
Ingore_border = False Ingore_border = True
pooled_out =
downsample.max_pool_2d(input=conv_out,
ds=poolsize, ignore_border=True)
LeNetConvPoolLayer
Class
Default in Theano library is False!
M&S
2. Stride in Pooling
Default in Theano
stride size = poolsize
Unduplicated!
M&S
2. Stride in Pooling
2
Default in Theano
stride size = poolsize
Unduplicated!
M&S
2. Stride in Pooling
2
Default in Theano
stride size = poolsize = (2,2)
Unduplicated!
M&S
2. Stride in Pooling
2
Default in Theano
stride size = poolsize = (2,2)
Unduplicated!
M&S
2. Stride in Pooling
2
Default in Theano
stride size = poolsize = (2,2)
Unduplicated!
M&S
2. Stride in Pooling
stride size = (1, 1)
6
M&S
2. Stride in Pooling
1
76
M&S
2. Stride in Pooling (Code)
76 8
6 7 8
3 3 4
pooled_out =
downsample.max_pool_2d(input=conv_out,
ds=poolsize, ignore_border=True)
pooled_out =
downsample.max_pool_2d(input=conv_out,
ds=poolsize, ignore_border=True, st = (1,1))
M&S
Activation Function in Convolutional Layer
self.output=T.tanh(pooled_out +
self.b.dimshuffle(‘x’,0,‘x’,‘x’)
Convolution Pooling Activation
LeNetConvPoolLayer
Class
M&S
Dimension Reduction 2D  1D
Input Image
Convolutional
Layer
Pooling
MLP
layer2_input = layer1_input.output.flatten(2)
1D - Output neurons
2D - Output neurons
M&S
Code for MLP in Theano
Input Image
Convolutional
Layer
Pooling
MLP layer2 = HiddenLayer( rng,
input=layer2_input,
n_in-nkerns[1] * 4 * 4,
n_out=500,
activation = T.tanh)
HiddenLayer
Class
Last output size for C+P
Number of node at Hidden layer
Activation function at Hidden layer
***In order to extend the number of Hidden Layer in MLP,
We need to make layer3 by copying this code***
M&S
Code for Softmax Output in Theano
Input Image
Convolutional
Layer
Pooling
MLP
Softmax Output
layer3 =
LogisticRegression( input=layer2.output,
n_in=500,
n_out=10)
LogisticRegression
Class
cost = layer3.negative_log_likelihood(y)
Number of node at previous
Hidden layer
Final Output size
Ex) 0, 1, 2, ,,, 9
Softmax activation function
M&S
CNN application in bioinformatics problem

More Related Content

PPTX
Introduction to CNN
PPTX
Image classification using CNN
PDF
Convolutional Neural Networks (CNN)
PPTX
Convolutional Neural Network and Its Applications
PPTX
AlexNet(ImageNet Classification with Deep Convolutional Neural Networks)
PPTX
CNN and its applications by ketaki
PPTX
Machine Learning - Convolutional Neural Network
Introduction to CNN
Image classification using CNN
Convolutional Neural Networks (CNN)
Convolutional Neural Network and Its Applications
AlexNet(ImageNet Classification with Deep Convolutional Neural Networks)
CNN and its applications by ketaki
Machine Learning - Convolutional Neural Network

What's hot (20)

PDF
Convolutional Neural Network Models - Deep Learning
PPTX
Resnet.pptx
PDF
Convolutional neural network
PPTX
Convolutional Neural Network - CNN | How CNN Works | Deep Learning Course | S...
PDF
Autoencoder
PPTX
Semantic segmentation with Convolutional Neural Network Approaches
PPTX
Autoencoders in Deep Learning
PDF
Overview of Convolutional Neural Networks
PDF
Mask-RCNN for Instance Segmentation
PPTX
Deep neural networks
PPTX
Deep Learning With Neural Networks
PDF
Object detection and Instance Segmentation
PPT
Artificial Neural Networks - ANN
PPTX
Object detection - RCNNs vs Retinanet
PPTX
U-Net (1).pptx
PPTX
Image classification with Deep Neural Networks
PPTX
Backpropagation And Gradient Descent In Neural Networks | Neural Network Tuto...
PPTX
Neural network
PDF
Semantic Segmentation - Fully Convolutional Networks for Semantic Segmentation
PPTX
Convolutional Neural Networks
Convolutional Neural Network Models - Deep Learning
Resnet.pptx
Convolutional neural network
Convolutional Neural Network - CNN | How CNN Works | Deep Learning Course | S...
Autoencoder
Semantic segmentation with Convolutional Neural Network Approaches
Autoencoders in Deep Learning
Overview of Convolutional Neural Networks
Mask-RCNN for Instance Segmentation
Deep neural networks
Deep Learning With Neural Networks
Object detection and Instance Segmentation
Artificial Neural Networks - ANN
Object detection - RCNNs vs Retinanet
U-Net (1).pptx
Image classification with Deep Neural Networks
Backpropagation And Gradient Descent In Neural Networks | Neural Network Tuto...
Neural network
Semantic Segmentation - Fully Convolutional Networks for Semantic Segmentation
Convolutional Neural Networks
Ad

Similar to Convolutional Neural Network (CNN) presentation from theory to code in Theano (20)

PPTX
Mnist report ppt
PDF
Mnist report
PPTX
Deep learning requirement and notes for novoice
PDF
Introduction to Applied Machine Learning
PPTX
Introduction to machine learning november 25, 2017
PDF
convolutional neural networks for deep learning
PDF
Hand Written Digit Classification
PPTX
CNN_AH.pptx
PPTX
CNN_AH.pptx
PDF
dfdshofdifhdifhdfhgfoighfgofgfgfgfgdfdfdfdf
PPTX
Deep Learning
PPTX
Digit recognizer by convolutional neural network
PDF
Faire de la reconnaissance d'images avec le Deep Learning - Cristina & Pierre...
PPTX
Deep Neural Networks for Computer Vision
PPTX
PyConZA'17 Deep Learning for Computer Vision
PDF
Deep Learning for Computer Vision - ExecutiveML
ODP
Convolution presentation
PPTX
Unit-5.pptx notes for artificial intelligence
PPTX
CNN.pptx
PPTX
cnn ppt.pptx
Mnist report ppt
Mnist report
Deep learning requirement and notes for novoice
Introduction to Applied Machine Learning
Introduction to machine learning november 25, 2017
convolutional neural networks for deep learning
Hand Written Digit Classification
CNN_AH.pptx
CNN_AH.pptx
dfdshofdifhdifhdfhgfoighfgofgfgfgfgdfdfdfdf
Deep Learning
Digit recognizer by convolutional neural network
Faire de la reconnaissance d'images avec le Deep Learning - Cristina & Pierre...
Deep Neural Networks for Computer Vision
PyConZA'17 Deep Learning for Computer Vision
Deep Learning for Computer Vision - ExecutiveML
Convolution presentation
Unit-5.pptx notes for artificial intelligence
CNN.pptx
cnn ppt.pptx
Ad

Recently uploaded (20)

PPTX
Qualitative Qantitative and Mixed Methods.pptx
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPT
Quality review (1)_presentation of this 21
PDF
Clinical guidelines as a resource for EBP(1).pdf
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PDF
Lecture1 pattern recognition............
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PPTX
IB Computer Science - Internal Assessment.pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
Database Infoormation System (DBIS).pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Qualitative Qantitative and Mixed Methods.pptx
climate analysis of Dhaka ,Banglades.pptx
Quality review (1)_presentation of this 21
Clinical guidelines as a resource for EBP(1).pdf
Galatica Smart Energy Infrastructure Startup Pitch Deck
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Lecture1 pattern recognition............
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
IB Computer Science - Internal Assessment.pptx
Miokarditis (Inflamasi pada Otot Jantung)
Introduction-to-Cloud-ComputingFinal.pptx
.pdf is not working space design for the following data for the following dat...
oil_refinery_comprehensive_20250804084928 (1).pptx
Database Infoormation System (DBIS).pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg

Convolutional Neural Network (CNN) presentation from theory to code in Theano

Editor's Notes

  • #24: Cross correlation 의 직관적 이해
  • #25: Cross correlation 의 직관적 이해
  • #26: Cross correlation 의 직관적 이해
  • #27: Cross correlation 의 직관적 이해
  • #28: Cross correlation 의 직관적 이해
  • #52: Cross correlation 의 직관적 이해