0% found this document useful (0 votes)
20 views53 pages

Convolutional Neural Network

The document discusses convolutional neural networks (CNNs) for image recognition. It explains that CNNs are better than fully connected networks for images because CNNs only connect neurons to a small region, reducing the number of weights. The key layers of a CNN are described as the convolution layer, ReLU layer, pooling layer, and fully connected layer. The convolution layer uses small filters that are convolved across the image, the ReLU layer introduces nonlinearity, and the pooling layer downsamples the image. These layers are stacked to learn hierarchical image features before the fully connected layer for classification. An example use case of identifying dogs vs cats from images is presented.

Uploaded by

21dce106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views53 pages

Convolutional Neural Network

The document discusses convolutional neural networks (CNNs) for image recognition. It explains that CNNs are better than fully connected networks for images because CNNs only connect neurons to a small region, reducing the number of weights. The key layers of a CNN are described as the convolution layer, ReLU layer, pooling layer, and fully connected layer. The convolution layer uses small filters that are convolved across the image, the ReLU layer introduces nonlinearity, and the pooling layer downsamples the image. These layers are stacked to learn hierarchical image features before the fully connected layer for classification. An example use case of identifying dogs vs cats from images is presented.

Uploaded by

21dce106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Agenda

• How a computer Reads an image?


• Why not fully connected networks for image recognition?
• What is Convolutional Neural Network ?
• How is Convolutional Neural Network Works?
• Convolutional Neural Network Use-Case.
How a Computer Reads an Image
How a Computer
sees an image

Pixel Values Of R,G,B


Why Not Fully Connected
Networks

Let’s see why we cannot use fully connected networks for image classifications
Why Not Fully Connected Networks
Image with Number of weights in the
28 x 28 x3 first hidden layer will be
Pixels 2352

Image with
200 x200 x 3 Number of weights in
pixels the first hidden layer
will be 120,000
Why Convolutional Neural
Networks?

Let’s Understand What is Convolutional Neural Network


Why Convolutional Neural Network ?
In case of CNN the neuron in layer will only be connected to a small region of the layer before it,
instead of all of the neurons in a fully-connected manner.
What is Convolutional
Neural Network?

Let’s Understand What is Convolutional Neural Network


What is Convolutional Neural Network?
Convolutional Neural Network (CNN, or ConvNet) is a type of feed-forward artificial neural
network in which the connectivity pattern between its neurons is inspired by the organization of
a animal visual cortex
How CNN Works?

Let’s Understand How Convolutional Neural Networks Work


How CNN Works?
Convolutional Neural Networks Have Following Layers:

 Convolution
 ReLU Layer
 Pooling

X
 Fully Connected
CNN

CNN
0
Trickier Case
Here, we will have some problems because X and 0 images won’t always have the same images.
There can be certain deformations. Consider the diagrams show below:

X
0
How CNN Works?

=
=
How CNN Works?
A Computer understands an image using numbers at each pixels.
In out example, we have considered that a black pixel will have a value of 1 and a white pixel will
have -1 value.
How CNN Works?
Using normal techniques, computers compare these images as:

+ =
How CNN Works?
CNN Compares the images piece by piece. The pieces that it look for are called features .
By finding rough feature matches, in roughly the same position in two images, CNN gets a lot
better at seeing similarity that whole-image schemes.

=
=
=
How CNN works?
We will be taking three features or filters, as shown below:
How CNN Works?

These are small pieces of the bigger image. We chose a feature and
put it on the input image, if it matches then the image is classified
correctly.
Convolution Layer
Steps involved in Convolution Layer

Here we will move the feature/filter to every possible position on the image.

Step - 1 Step - 2

Line up the feature and the image. Multiply each image pixel by the
corresponding feature pixel.
Multiplying the corresponding Pixel Values
1x1=1
Steps involved in Convolution Layer
Here we will move the feature/filter to every possible position on the image.

Step - 1 Step - 2

Line up the feature and the image. Multiply each image pixel by the
corresponding feature pixel.

Step - 3 Step - 4

Divide by total number of pixels in the


Add Them Up.
feature.
Adding And Dividing by the total numbers of Pixels
Creating a Map to put the value of the filter
Now to keep track of were that feature was, we create a map and put the values of the filter at
that place.
Sliding the filter Throughout the image
Now, using the same feature and move it to another location and perform the filtering again.
Convolution Layer
Now we will put the value of the filter at that position.
Convolution Layer Output
Similarly, we will move the feature to every other positions of the image and will see how the
feature matcher that area. Finally we will get an output as:
Convolution Layer output
Similarly, we will perform the same convolution with every other filters
ReLu Layer
ReLU Layer
 In this layer we remove every negative values from the filtered images and replaces it with
zero’s.
 This is done to avoid the values from summing up to zero.

Rectified Linear unit (ReLU) transform function only activates a node if the input is above a
certain quantity, while the input is below zero, the input zero, but when the input rises above a
certain threshold, it has a linear relationship with the dependent variable.

X F(x)=x F(x)
-3 F(-3)=0 0
-5 F(-5)=0 0
3 F(3)=3 3
5 F(5)=5 5
Removing Negative Values
Removing Negative Values
Output for one feature
Output for All Features
Pooling Layer
Pooling Layer
In this we shrink the image stack into a smaller size steps:

1. Pick a window size (usually 2 or 3).


2. Pick a stride (usually 2)
3. Walk your windows across your filtered images.
4. From each window take the maximum value.

Let’s preform pooling with a window size 2 and stride 2


Calculating the maximum Value in each Window

Let’s start with our first filtered image


In our first window the maximum or highest value is 1, so we track that and move the window
two strides.
Moving the window Across the Entire Image
Output After Passing Through Pooling Layer
Stacking up the Layers
Stacking up the Layers
Stacking up the Layers
Fully Connected Layer
This is final layer where the actual classification happens
Here we take our filtered and shirked images and put them into a single list
Output
When we feed in, ‘X’ and ‘O’. Then there will be some element in the vector that will be high.
Consider the image below, as you can see for ‘X’ there are different element that high and
similarly, for ‘O’ we have different elements that are high.
Prediction

Consider the below list of a new input image:


Prediction

Consider the below list of a new input image:

Let’s compare this with the list of ‘X’ and ‘0’


Comparing the input Vector with X

Sum Sum

4.56
/ 4.56

0.91

Input Image Vector for ‘X’


Comparing the input Vector with X

Sum Sum

2.07
/ 4

0.51

Input Image Vector for ‘0’


Result

.91 .51

The Input image is classified as ‘X’


CNN Use-Case
Dog and Cat Identifier

Training

DOG
Input
Implementing the Use-Case
Download Function to encode Resize the image to 50x50 pixel Split the data, 24,500 images for
the dataset the labels and read as greyscale training and 500 for testing

Calculate loss
function, it is Reshape the data appropriately
categorical cross Build Model
for Tensor Flow
entropy

Adam as optimizer
with learning rate Train the Deep Neural Net for
set to 0.001. 10 epochs

Make predictions
Thank You

You might also like