8 CNN Example
8 CNN Example
8 CNN Example
Networks_Ex
Dr. Dinesh Kumar Vishwakarma
Professor, Department of Information Technology
Delhi Technological University, Delhi
Email: [email protected]
Web page: http://www.dtu.ac.in/Web/Departments/InformationTechnology/faculty/dkvishwakarma.php
Biometric Research Laboratory
http://www.dtu.ac.in/Web/Departments/InformationTechnology/lab_and_infra/bml/
3/7/2023 1
What is CNN?
3/7/2023 2
CNN Benefits
• Equivariant activities: Replicated features do not make the neural
activities invariant to translation. The activities are equivariant.
Representation Translated
by active representation
neurons
translated
image
image
3/7/2023 4
Possible Case
3/7/2023 5
How CNN Works?
3/7/2023 6
How CNN Works?
3/7/2023 7
How CNN Works?
Gives an idea
3/7/2023 8
How CNN Works?
First Filter
Second Filter
Third Filter
3/7/2023 9
How CNN Works?
3/7/2023 10
How CNN Works?
3/7/2023 11
Convolutional Layer
3/7/2023 12
Operations Involved in Convolution Layer
• Move filter over the image at every possible position.
• Multiply each image pixel by corresponding feature pixel.
Similarly
3/7/2023 13
Operations Involved in Convolution Layer…
O/P of
Conv
Layer
for first
filter
• Adding all the multiplied values of filter at every move.
• Divide the sum by total number of pixels.
3/7/2023 14
Output of Convolutional Layer
3/7/2023 15
Activation Layer: ReLU
3/7/2023 16
ReLU: Removes the Negative Values
3/7/2023 17
Pooling Layer
3/7/2023 18
Max Pooling of size: 2x2, Stride : 2
4x4
.77
7x7
3/7/2023 19
Max Pooling of size: 2x2, Stride : 2
.77
7x7 4x4
7x7 4x4
4x4
7x7
3/7/2023 20
Stacking of Layers
Convolutional Layer
3/7/2023 21
Practical CNN Model
• Most of the practical CNN models have more number of
layers.
2x2
2x2
2x2
3/7/2023 22
Fully Connected Layer
• Actual Classification Occurs at FC layer
Flattened the
final output
layer
3/7/2023 23
Output
1 1
2 2
3 3
4 4
5 5
6 6
7
“1” at
7
8 8
9 9
10 10
11 11
12 12
3/7/2023 24
Prediction
1
Now Network
2
3
is training
4
and gives
5
prediction for
6 a Test sample
7
10 Is is “X” or “O”?
11
12
Lets Compare
3/7/2023 25
Prediction: Compare with ‘X’ and ‘O’
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
For ‘X’
3/7/2023 26
Prediction: Compare with ‘X’ and ‘O’
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
For ‘O’
3/7/2023 27
Result: Compare with ‘X’ and ‘O’
What is result?
Classified
as “X”
3/7/2023 28
CNN for Edge Detection
3/7/2023 29
Implementation of CNN
The CIFAR-
10 dataset:
This dataset
consists of
60000 32x32
colour images
in 10 classes,
with 6000
images per
class.
3/7/2023 30
Model of CNN
3/7/2023 31
Implementation in TensorFlow
def createModel():
model = Sequential()
# The first two layers with 32 filters of window size 3x3
model.add(Conv2D(32, (3, 3), padding='same', activation='relu', input_shape=input_shape))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(nClasses, activation='softmax'))
return model
3/7/2023 32
References
• https://www.youtube.com/watch?v=umGJ30-15_A
3/7/2023 33