Convolutional Neural Network for beginners.
By: Ranjit Singh Rathore
Tags: Deep Learning, Neural Network Algorithm, Artificalintelligence, Computer Vision

Computer Vision is trending nowadays in the market , mainly due to Deep learning and its evolution . Computers are now able to extract more information from the images , they are playing a vital role in our society and have lots of game changing real world applications .So here we are going to cover the base of CNN(Convolutional Neural Network).

In this blog ,we are going to cover following topics:

What is convolutional neural network?

convolution operations in CNN.

Padding in CNN.

Pooling layers in CNN.

Basic Architecture of CNN.

Data Augmentation in CNN.

Application of CNN.

Why we use CNN instead of ANN in visual problem.

What is Convolutional Neural Network (CNN) ?

Convolutional neural network (CNN) is the type of deep learning neural networks , which use the mathematical function Convolution as its base. CNN is commonly used when the inputs are in the visual form like images , videos ,etc.

Convolution Operation in CNN.

In mathematical term , a convolution operation is a mathematic function which accepts two function ,let say f1 and f2 ,and produce a new function f3 ,which will be ( f1 * f2 ) , which express how shape and size of one function changed by other one.

Convolution operations have many application in different domains like probability, statistic , computer vision , signal processing ,etc.

Specifically in CNN , the inputs to the network are mainly the images and videos frames , so the input format is an matrix containing the pixel value of the images.

So, the convolution operations are performed on the matrix . One matrix is the Image matrix and the second matrix is the filter.A

Simple Convolution operation on the two matrix (image matrix and filter matrix ).Source

Generally , (M)the size of output matrix we get , after applying a simple convolution operation on two matrixes i.e. Image matrix (have size N) and filter matrix (having size F) with a padding P is:

O = N + ( 2 * P ) — F + 1

Padding in CNN.

The problem with applying convolution operation on the image matrix is that , the size of the output matrix is reduced . Which means there is a loss of information .

For example , Initially we do have a (6 * 6) image matrix ,but after applying a filter , we get ( 4 * 4 ) output image , it means we have lose some information . To Overcome this problem we used padding.

Padding refers to the amount of pixels added to an image when it is being processed by the kernel of a CNN. For example, if the padding in a CNN is set to zero, then every pixel value that is added will be of value zero. If, however, the zero padding is set to one, there will be a one pixel border added to the image with a pixel value of zero.

From the above image , we can see how applying padding can save the size of image. padding= 1 ,N = 5 , F = 3:

N + (2 * Padding)-F + 1 => 5 + (2*1)-3 + 1 = 5+ 2–3+1= 5

Now the input matrix is of 5*5 and the output matrix is of size 5*5 . So no information has loosed here.

Pooling layers in CNN.

Pooling technique are used to reduce the dimension of the matrix i.e. the number of parameters , and also to remove all the noisy feature from the feature matrix , so that only important feature can be used for further process.

There are multiple pooling layers present , but the most commonly used are:

Max-pooling : If taking 2*2 submatrix in input image matrix ,then returning the max-value from it.

Sum-pooling : If taking 2*2 submatrix in input image matrix, then returning the sum of all value from it.

Average-pooling : If taking 2*2 submatrix in the input image matrix , then returning the average value from it.

Average Pooling. Source

Architecture of Simple CNN

A simple CNN consist of an input and output layer , also hidden layers in between. The hidden layers consist of Convolutional layers that convolve with multiple filters , producing the feature matrix then passed to the activation function (commonly ReLU is used) , and is subsequently followed by additional convolutions such as pooling layers, fully connected layers and normalization layers.

Data Augmentation in CNN.

Data Augmentation is the technique by which we can create multiple forms of the our input images by applying some transformation on the images.

For example Flipping the image, horizontal shifting , vertical shifting , rotations at different angle ,zooming in and out , etc.

We usually use data augmentation technique when we have lesser data for our problem , or if our model is showing overfitting-conditions.

Getting different variation of a image by applying Data Augmentation techniques(Like zoom in out, shifting , rotation , etc. ) Source of image

Data Augmentation can drastically increase the size of our dataset , just by using same images. Because of data augmentation , our CNN model will be robust and invariant , and will produce good results.

Applications of CNN.

Convolutional neural network can be used everywhere , where the inputs are in the visual form i.e. images, videos ,etc.

CNN brought the boost in the field of Computer visions.

Some of the most common applications of CNN are :

Object Classification: We can use a CNN architecture to classify the our objects.

Multi-class classification using CNN. Source

Animal Classification using CNN .Source

Object Detection : Object Detection includes both the object classification and object localization .CNN are also used in Object detection application like in Self-driving car to detect the persons ,vehicle , etc.

Object detection using CNN. Source

Object Recognition : Face Recognition is an example of object recognition , and can be achieved using CNN.

Face Recognition . Source

There are lots of applications of CNN in different domains .

Why we use CNN instead of ANN .

We must use CNN instead of ANN , when our input data are in the visual form i.e. Image and video format.

Some common reason to use CNN over ANN in visual data problems:

Reduce the number of parameters: Using CNN , can drastically reduce the number of parameters in our network.

Using CNN , can drastically reduce the number of parameters in our network. Reduce the training time of model : Since the number of parameters are reduced , now our model takes less time to train on the data.

: Since the number of parameters are reduced , now our model takes less time to train on the data. More Accurate and robust: ANN works by using the pixel value of the image as its base , due to which we cannot used this trained model in real world scenario , since the image can differ in size, light intensity , color ,shades ,which will give the wrong prediction. But CNN uses the filter and convolution operations , and use the low level features of images like all edges , smoothness , curves and many more features for prediction . Now this approach is robust and more accurate in real world scenario.

That’s all for this blog ,this was the basis introduction of CNN for beginners. Thank you!

Gain Access to Expert View — Subscribe to DDI Intel