Understanding CNNs
By: Vandan Gorade
Tags: Machine, Computer Vision, Convolutional Network, Neural Networks, Data Science

CNN on MNIST

What do you think when you as a human look at a world?

We can easily tell what there in the world its color, shape, size, texture…everything.

But How?

Human brains has visual areas in visual cortex which are responsible for detecting motion, stereo, edges, color, texture segregation, segmentaion and so on.

Now the question is how do we enable machines view the world as we humans do, perceive it in a similar manner and even use the knowledge for multiple tasks such as Image and Video Classification, Segmentation, image generation, Recommendation…and so on. The answer is Computer Vision one of the many fields in Artificial Intelligence.The advancements in Computer Vision with Deep Learning has been constructed and perfected with time, primarily over one particular algorithm — a Convolutional Neural Network.

Convolutional Neural Networks

(CNNs) are analogous to traditional ANNs.

In the ANNs the input is goes through series of hidden layers. The layers are consist rather they are made of set of neurons and all layers are fully connected to the neurons of previous layer. The only notable difference between CNNs and traditional ANNs is that CNNs are primarily used in the field of computer vision.

Artificial Neural Network

Why not ANNs for image related tasks?

Well, the answer is simple

Hardware Dependence i.e high computational power required. CNNs tends to give better accuracy than ANNs.

But why does it matter? Surely we could just increase the number of hidden layers in our network, and perhaps increase the number of neurons within them?

The simple answer is NO. There are two reasons,

we do not have unlimited Computational Power and time to train these huge ANNs. The second reason is stopping or reducing the effects of Overfitting. Overfitting is basically when a network is unable to learn effectively due to a number of reasons. Overfitting when model learns noise present in training data to the large extent and it negatively impact on our performance. Overfitting can also happen when we have less amount of data for our model to train on.

CNN Architecture

CNN Architecture for handwritten digits

Overall Architecture

The input layer will hold the pixel values in image The convolutional layer will determine the output of neurons of which are connected to local regions of the input through the calculation of the scalar product between their weights and the region connected to the input volume. The rectified linear unit (commonly shortened to ReLu) aims to apply an ‘elementwise’ activation function such as sigmoid to the output of the activation produced by the previous layer. The pooling layer will then simply perform downsampling along the spatial dimensionality of the given input, further reducing the number of parameters within that activation. The fully-connected layers will then perform the same duties found in

standard ANNs and attempt to produce class scores from the activations,

to be used for classification. It is also suggested that ReLu may be used

between these layers, as to improve performance.

Through this simple method of transformation, CNNs are able to transform the original input layer by layer using convolutional and downsampling techniques to produce class scores for classification and regression purposes.

Input to CNN

RGB image(4,4,3)

The image on L.H.S is the RGB image i.e the image is separeated by three colors Red, Green, Blue. Image can be separated by many other color spaces for example, HSY, CMYK.

The neurons that the layers within the CNN are comprised of neurons organised into three dimensions, the spatial dimensionality of the input (height, width, depth). depth is the number of channels.

Convolutional layer

what is convolution?

Convolution on image

matrix(f = (5,5,1)) * kernel/filter(g=(3,3,1)) = convolve feature

Mathematical definition:

convolution is a mathematical operation on two functions (f and g) that produces a third function expressing how the shape of one is modified by the other. The term convolution refers to both the result function and to the process of computing it.

Intuitive definition:

Convolution is the first layer to extract features from an input image. Convolution preserves the relationship between pixels by learning image features using small squares of input data. It is a mathematical operation that takes two inputs such as image matrix(f) and a filter or kernel(g).

why kernel(g) shifts on matrix(f) total 9 times and also only in right direction?

It happens because the Stride length = 1.

Now what in the world is stride?

Stride is the number of pixels shifts over the input matrix. When the stride is 1 then we move the filters to 1 pixel at a time. When the stride is 2 then we move the filters to 2 pixels at a time and so on.

It helps to reduce size of matrix and therefore it also use for compression of images and video data.

Let’s look at more practical example,

I

n this zoomed in image of the dog, we first start with the patch outlined in red. The width and height of our filter define the size of this square.

We then move the square over to the right by a given stride (2 in this case) to get another patch.

What if image has multiple channels(eg.RGB)?