Convolutional Neural Network
Convolutional Neural Network
or 4 legs. Similarly, the computer can perform image classification by looking for low-level
features such as edges and curves and then building up to more abstract concepts through a
series of convolutional layers. This is a general overview of what CNN does. Let's get into
the specifics.
2.1: Convolutional
ConvNets derive their name from the “Convolution Operation”. The Convolution in case of
ConvNet is to extract features from the input images. Convolution preserves the spatial
relationships between pixels by learning image features using Small Square of input data.
As we discussed above, every image can be considered as a matrix of the pixel value.
Consider a 5*5 image whose pixel values are only 0 & 1 (note that for a grayscale image,
pixel values range from 0 to 255, where pixel values are only 0 & 1.
Similarly, Feature Detector Detect the Every single part of the input image and then result
from the show in Feature map which base on the match of feature Detector of the input
image.
CNN terminology, the 3×3 matrix is called a 'filter' or 'kernel' or 'feature detector' and the
matrix formed by sliding the filter over the image and computing the dot product is called the
©Wavy AI Research Foundation 5
Convolutional Neural Network
'Convolved Feature' or 'Activation Map' or the 'Feature Map'. It is important to note that
filters act as feature detectors from the original input image.
Depth:
Depth corresponds to the number of filters we use for the convolution operation. In the
network shown in Figure below, we are performing the convolution of the original boat
image using three distinct filters, thus producing three different feature maps as shown. You
can think of these three feature maps as stacked 2d matrices, so, the 'depth' of the feature map
would be three. The more numbers of filters the more accurate result.
Stride:
Stride is the number of pixels by which we slide our filter matrix over the input matrix. When
the stride is 1 then we move the filters one pixel at a time. When the stride is 2, then the
filters jump 2 pixels at a time as we slide them around. Having a larger stride will produce
smaller feature maps.
Zero-Padding:
Sometimes, it is convenient to pad the input matrix with zeros around the border, so that we
can apply the filter to bordering elements of our input image matrix. A nice feature of zero
paddings is that it allows us to control the size of the feature maps. Adding zero-padding is
also called wide convolution, and not using zero-padding would be a narrow convolution.
©Wavy AI Research Foundation 6
Convolutional Neural Network
Input = output
Padding >>> same >>> padding to make output size same as input size.
ReLU is an element-wise operation (applied per pixel) and replaces all negative pixel values
in the feature map by zero. The purpose of ReLU is to introduce non-linearity in our ConvNet
since most of the real-world data we would want our ConvNet to learn would be non-linear
(Convolution is a linear operation — element-wise matrix multiplication and addition, so we
account for non-linearity by introducing a non-linear function like ReLU).
©Wavy AI Research Foundation 7
Convolutional Neural Network
As shown below image we apply the Relu operation and he replaces all the negative numbers
by 0.
In the case of Max Pooling, we define a spatial neighborhood (for example, a 2×2 window)
and take the largest element from the rectified feature map within that window. Instead of
taking the largest element we could also take the average (Average Pooling) or sum of all
elements in that window. In practice, Max Pooling has been shown to work better.
Below shows an example of Max Pooling operation on a Rectified Feature map (obtained after
convolution + ReLU operation) by using a 2×2 window.
©Wavy AI Research Foundation 8
Convolutional Neural Network
2.3: Flattening
Flattening is the process of converting al the resultant 2-dimensional arrays into a single long
continuous linear vector.
©Wavy AI Research Foundation 9
Convolutional Neural Network
1. Convolution
2. Pooling
3. Flattening
4. Full Connection
So Flattening is become the input of Artificial Neural Network which is used for the
backpropagation Method.
©Wavy AI Research Foundation 10
Convolutional Neural Network
The output from the convolutional and pooling layers represent high-level features of the input
image. The purpose of the Fully Connected layer is to use these features for classifying the
input image into various classes based on the training dataset. For example, the image
classification task we set out to perform has four possible outputs as shown in Figure below
(note that Figure 14 does not show connections between the nodes in the fully connected
layer)
Apart from classification, adding a fully-connected layer is also a (usually) cheap way of
learning non-linear combinations of these features. Most of the features from convolutional
and pooling layers may be good for the classification task, but combinations of those features
might be even better. The sum of output probabilities from the Fully Connected Layer is 1.
This is ensured by using the Softmax as the activation function in the output layer of the Fully
Connected Layer. The Softmax function takes a vector of arbitrary real-valued scores and
squashes it to a vector of values between zero and one that sums to one.
©Wavy AI Research Foundation 11
Convolutional Neural Network
Note that in Figure below, since the input image is a boat, the target probability is 1 for Boat
class and 0 for the other three classes, i.e.
Step2: The network takes a training image as input, goes through the forward propagation step
(convolution, ReLU, and pooling operations along with forwarding propagation in the Fully
Connected layer) and finds the output probabilities for each class.
Let’s say the output probabilities for the boat image above are [0.2, 0.4, 0.1, 0.3]
Since weights are randomly assigned for the first training example, output probabilities are
also random.
Step3: Calculate the total error at the output layer (summation over all 4 classes)
Step4: Use Backpropagation to calculate the gradients of the error concerning all weights in
the network and use gradient descent to update all filter values/weights and parameter values
to minimize the output error.
The weights are adjusted in proportion to their contribution to the total error.
When the same image is input again, output probabilities might now be [0.1, 0.1, 0.7, 0.1],
which is closer to the target vector [0, 0, 1, 0].
This means that the network has learned to classify this particular image correctly by adjusting
its weights/filters such that the output error is reduced.
Parameters like the number of filters, filter sizes, the architecture of the network, etc. have all
been fixed before Step 1 and do not change during the training process — only the values of
the filter matrix and connection weights get updated.
Step5: Repeat steps 2–4 with all images in the training set.
Selection of Image
Image X Image O
In convolutional networks, you look at an image through a smaller window and move that
window to the right and down. That way you can find features in that window, for example, a
horizontal line or a vertical line or a curve, etc… What exactly a convolutional neural
network considers an important feature is defined while learning.
Wherever you find those features, you report that in the feature maps. A certain combination
of features in a certain area can signal a larger, more complex feature exists there.
For example, your first feature map could look for curves. The next feature map could look at
a combination of curves that build circles.
©Wavy AI Research Foundation 14
Convolutional Neural Network
There are three filters so there will be three convolutional layers stored in the form of the
stack
In CNN convolutional layer, the 3×3 matrix called the ‘feature filter’ or ‘kernel’ or ‘feature
detector’ sliding over the image and the matrix formed will be the convolutional layer. It is
important to note that filters act as feature detectors from the original input image. Image X
matching with filter # 1 with a stride of 1.
The pixel values of the highlighted matrix will be multiplied with their corresponding pixel
values of the filter and then takes the average.
= 0.77
©Wavy AI Research Foundation 16
Convolutional Neural Network
Here you will see how the filter shifts on pixels with a stride of 1.
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1 1 -1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 1 -1
-1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1
-1 -1 -1 -1 1 -1 -1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 x 1 -1 x -1 -1 x -1 -1 1 1
1 x -1 -1 x 1 -1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-1 1 -1 -1
-1 -1 1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 x 1 -1 x -1 -1 x -1 -1 1 1
-1 x -1 -1 x 1 -1 x -1 = 1 -1 1
-1 x -1 -1 x -1 -1 x 1 1 1 -1
= 0.33
0.77 -0.11 0.11 0.33 0.55 -0.11 0.33
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 -1 -1 1 -1 -1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 1 -1 -1 -1 1 -1 -1 -1 1 -1
-1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 x 1 -1 x -1 -1 x -1 -1 1 1
-1 x -1 -1 x 1 -1 x -1 = 1 -1 1
-1 x -1 -1 x -1 1x1 1 1 1
= 0.55
0.77 -0.11 0.11 0.33 0.55 -0.11 0.33
0.55
©Wavy AI Research Foundation 44
Convolutional Neural Network
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 -1 -1 1 -1 -1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1
-1 x 1 -1 x -1 -1 x -1 -1 1 1
-1 x -1 -1 x 1 1 x -1 = 1 -1 -1
-1 x -1 1 x -1 -1 x 1 1 -1 -1
= -0.11
0.77 -0.11 0.11 0.33 0.55 -0.11 0.33
0.55 -0.11
©Wavy AI Research Foundation 45
Convolutional Neural Network
-1 -1 -1 -1 -1 -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1 -1 -1 -1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 x 1 -1 x -1 -1 x -1 -1 1 1
-1 x -1 -1 x 1 1 x -1 = 1 -1 -1
-1 x -1 1 x -1 -1 x 1 1 -1 -1
= -0.11
0.77 -0.11 0.11 0.33 0.55 -0.11 0.33
-0.11
©Wavy AI Research Foundation 51
Convolutional Neural Network
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 -1 -1 1 -1 -1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1
-1 x 1 -1 x -1 1 x -1 -1 1 -1
-1 x -1 1x1 -1 x -1 = 1 1 1
1 x -1 -1 x -1 -1 x 1 -1 1 -1
= 0.11
-0.11 0.11
©Wavy AI Research Foundation 52
Convolutional Neural Network
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 -1 -1 1 -1 -1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1
-1 x 1 1 x -1 -1 x -1 -1 -1 1
1 x -1 -1 x 1 -1 x -1 = -1 -1 1
-1 x -1 -1 x -1 -1 x 1 1 1 -1
= -0.11
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 -1 1 -1 1 -1 -1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-1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 -1 1 -1 1 -1 -1 -1
-1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 1
-1 -1 -1 1 -1 1 -1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
After repeating the same steps of the convolutional layer on image “X” with filter 3, we get
Apply ReLu activation Function on Convolutional Layer 1 to convert all the negative values
to zero
Repeat the same steps of max pooling for convolutional layer 2, we get
Repeat the same steps of max pooling for convolutional layer 3, we get
Repeat the same steps of further max pooling for use in fully connected layer
1.00 0.55
0.55 0.55
Repeat the same steps of further max pooling for use in fully connected layer
0.55 1.00
1.00 0.55
3.5 Flattening:
In this step, we converting all the resultant 2-dimensional arrays into a single long continuous
linear vector.
1.00
1.00
1.00
0.55
0.55
0.55
Now, these single long continuous linear vectors are input nodes of our full connection layer.
©Wavy AI Research Foundation 77
Convolutional Neural Network
White cells are votes depends on how strongly a value can predict “X”
These are the input node so after that we doing backpropagation. For backpropagation, you
can see chapter 2 which we explain backpropagation in details (we not going
backpropagation here because we already have done in chapter 2)
©Wavy AI Research Foundation 78
Convolutional Neural Network
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 1 1 1 -1 -1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 1 -1 -1 -1 -1 -1 1 -1
-1 -1 1 -1 -1 -1 1 -1 -1
-1 -1 -1 1 1 1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
After repeating the procedure of training the convolutional neural network the same as we
had done for training image X, we get
0.55
1.00
1.00
0.55
0.55
0.55
0.55
0.55
1.00
0.55
0.55
1.00
White cells are votes depends on how strongly a value can predict “O”
©Wavy AI Research Foundation 79
Convolutional Neural Network
Prediction Example
We feed an image into the convolutional neural network and we don’t know whether it is X
or O.
Now we get new input and we don't know what it is and want to decide the way this works is
the input goes through all of our convolutional our rectified linear unit and pooling layer and
at the end we get,
0.9
0.65
0.45
0.87
0.96
0.73
0.23
0.63
0.44
0.89
0.94
0.53
©Wavy AI Research Foundation 80
Convolutional Neural Network
1.00 0.9
0.55 0.65
0.55 0.45
1.00 0.87
1.00 0.96
0.55 0.73
0.55 0.23
0.55 0.63
0.55 0.44
1.00 0.89
1.00 0.94
0.55 0.53
= 0.912
So our CNN predicts the input image as X with a prediction rate of 91 percent
©Wavy AI Research Foundation 81
Convolutional Neural Network
0.55 0.9
1.00 0.65
1.00 0.45
0.55 0.87
0.55 0.96
0.55 0.73
0.55 0.23
0.55 0.63
1.00 0.44
0.55 0.89
0.55 0.94
1.00 0.53
= 0.5175
So our CNN predicts the input image as O with a prediction rate of 51 percent
As
Prediction rate for X > Prediction rate of O
91 > 51
So,
The image we input for prediction into our convolutional neural network is X
©Wavy AI Research Foundation 82
Convolutional Neural Network
Dataset sample:
Cat Dog
In this step, we import Keras library and packages for building the Convolutional Neural
Network model. First, we import the Sequential module which is used for initializing our
model. Second is Convolutiona2D is the package that we’ll use for the first step of making
the CNN that is the convolution step in which we add convolutional layers So here we are
working with images which are only 2 dimensions there we use convolution2D( incase of
video we use 3D). Then the next package is MaxPooling2D that's a package that we'll use to
proceed to step to the pooling step that will add our pooling layers. The next package is
Flatten this is the package that we will use in step 3 flattening in which we convert all the
pooled feature maps that we created through convolution and max-pooling into the large
feature vector that is then becoming the input of our fully connected layers. And then finally
©Wavy AI Research Foundation 83
Convolutional Neural Network
the last package which Dense package this is the package we use to add the fully connected
layer.
In this step, we initialize our Convolutional Neural Network model to do that we use
sequential modules.
Convolution Step:
In this step, we add a convolution step and this is the first step of CNN. Here in
Convolution2D, we pass several arguments in this module. First arguments which we pass
here feature detector (32, 3, 3) that’s mean we create 32 feature detectors of three by three
dimensions and therefore our convolutional layers composed of 32 feature maps. Next
arguments are input shape that’s the shape of input image on which we are going to apply
feature detectors through the convolution operation in this arguments we convert all images
into same formats here 64 and 64 are dimension and 3 is number of channels because we are
working with colored images that's why we use 3 number channels correspond to RGB (
incase of black & white image we use 1 number of channel). And the last argument which we
pass here is relu activation function the relu function is used to replace the negate pixel value
by 0(As we understand in mathematical part of CNN intuition)
Pooling Step:
In this step, we add the pooling layer of our CNN model pooling layer is reducing the size of
the feature map( the size of the feature map is divided by 2 when we apply the pooling layer).
Here we passed only one argument which is pool size and define 2 by 2 dimension because
we don't want to lose any information about the image there we take the minimum size of the
pool.
©Wavy AI Research Foundation 84
Convolutional Neural Network
In this step, we add a second convolution layer and pooling layer to make a mode more
efficient and produce some good accuracy.
Flatten Step:
In this step, we convert Max pooling 2D into a single long continuous linear vector to make
an input node of fully connected layers.
In this step, we use the Dense model to add a different layer. The parameter which we pass
here first is ouptu_dim=6 which defines hidden layer=128 and last arguments Third is
activation= relu here in hidden layer we use relu activation.
After adding a Hidden layer we add an output layer in full connection layer out_dim= 1
which means one output node here we use the sigmoid function because our target attribute
has a binary class which is cat or dog that's why we use sigmoid activation function.
In this step we compile the CNN to do that we use the compile method and add several
parameters the first parameter is optimizer = Adam here use the optimal number of weights.
So for choosing the optimal number of weights, there are various algorithms of Stochastic
Gradient Descent but very efficient one which is Adam so that's why we use Adam optimizer
here. The second parameter is loss this corresponds to loss function here we use
binary_crossentropy because if we see target attribute our dataset which contains the binary
©Wavy AI Research Foundation 85
Convolutional Neural Network
value that's why we choose the binary cross-entropy. The final parameter is metrics its list of
metrics to be evaluated by the model and here we choose the accuracy metrics.
First import a class that will allow us to use this image data Generator function. This class
called Image Data Generator and we import this class from Keras image preprocessing.
2.1.1: Train_datagen
This step is like a data preprocessing which we did chapter 2 ANN but Now we are working
with an image that's why we doing Image Augmentation. Here we pass several arguments
first is rescale is like a feature scaling which doing in data preprocessing here our image 0 to
255-pixel value and we rescale into 0 & 1. Then next is Shear_range( Shear angle in the
counter-clockwise direction in degrees) that to apply random transactions and we will keep
this 0.2. zoom_range that will apply some random zoom and we keep 0.2 value. And then
last is horizontal_flip Randomly flip inputs horizontally
2.1.2: Test_datagen
In this step, we import the images that we want to train. Remember our dataset contains 1000
images 8000 for train and 2000 for test and here first we import our images from the working
directory that we want to train. Then target size here 64 by 64 that's expected CNN which we
defined earlier in Building the CNN part. Then batch size that the size of batch in which some
©Wavy AI Research Foundation 86
Convolutional Neural Network
random sample of our image will be included and that contains the number of images that
will go through the CNN after which the weight will be updated. And finally, the class mode
that the parameter indicating if your class is dependent variable is binary or has more than
two categories and therefore since two-class here cat & dog that's why class mode is binary
here that we use here.
First arguments which we pass here is train set which contains 8000 images belongs to 2
class second is stepper epoch that is the number of the image we in our training set because
remember all the observation of the training set pass through CNN during each epoch since
we have 8000 images that's why 8000 here. Then the number of epoch you want to choose to
train our CNN here we take only 1 because our purpose is just to understand we suggest to
take more than 50 for good accuracy. And then validation data that correspond to the test set
on which we want to evaluate the performance of our CNN. And last are validation steps that
correspond to the number of the image in our test set and that is 2000.
Here we go we obtain 80% for the training set and 81% for the test set.
In this step, we import libraries the first library which we import here is numpy used for
multidimensional array and the second is image package from Keras used for import the
image from the working directory.
©Wavy AI Research Foundation 87
Convolutional Neural Network
In this step, we import our single image we don't know either is cat image or dog image (like
in mathematical part when we train images 0 and X and then make a prediction X). Here we
pass two arguments first is image load and second is target size. Here we set target size 64 by
64 as expected our CNN model.
In this step, we set the dimension of our image 2D (64, 64) into the 3D array(64, 64, 3)
exactly as input shape that’s the architecture of input shape.
We are working with the single image we directly make a prediction then will raise an error
which expected convolution 2d input_1 to have 4 dimensions to do that we modify the test
image into 4 dimensions.
Make a prediction
In this step, we predict a single image
©Wavy AI Research Foundation 88
Convolutional Neural Network
So here we go cat corresponds to 0 and dog corresponds to 1 so our image is a dog. Perfect so
that's mean the prediction of our CNN model for the first image of cat & dog is correct
because the image contains the dog
©Wavy AI Research Foundation 89
Convolutional Neural Network
The CIFAR-10 dataset (Canadian Institute For Advanced Research) is a collection of images
that are commonly used to train machine learning and computer vision algorithms. It is one of
the most widely used datasets for machine learning research. The CIFAR-10 dataset contains
60,000 32x32 color images in 10 different classes. The 10 different classes represent
airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships, and trucks. There are 6,000 images
of each class.
The 10 different classes represent airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships,
and trucks. There are 6,000 images of each class.
Here are the first 10 sample images from the training data. The images have a structure of (32,32,3) which
correspond to (width, height, RGB)
©Wavy AI Research Foundation 91
Convolutional Neural Network
We are going to use the deep convolutional neural network to classify the images. Instead of
class indices, we will use one-hot encoded vectors to represent the labels of the samples.
©Wavy AI Research Foundation 92
Convolutional Neural Network
A simple way to normalize our data is to scale the pixel values between 0 to 1 range.
We used the Stochastic Gradient Descent algorithm (SGD) to optimize the weights on the
backpropagation. Set the momentum parameter as 0.9, and just leave the others as default.
Visualize loss:
©Wavy AI Research Foundation 95
Convolutional Neural Network