BASICS ABOUT CONVOLUTIONAL NEURAL NETWORK (CNN)

 






Hey guys. In the last post, I gave a brief idea about the neural network where I explained about the very basic idea about neural networks. Today I would discuss a particularly interesting subtopic of neural network - CNN.

CNN is a breath-taking architecture (at least in my opinion) which is used to process visual information like images and videos. Have you ever wondered how does face recognition identify that it is you? It is through computer vision, a concept which is heavily backed by CNN.

So let’s see how it works, shall we?

Just think about it. How do you identify the number 8? Two circles on top of each other, right?

What about a cat? If it has two eyes, four legs, fur and paws then it is most likely a cat.

If you see it carefully, we are identifying different features inside an image. After analysing the features, we come to a conclusion about the object in the image.

This is exactly what CNN does.

It extracts features from the images and from its past experiences, it classifies the image as a dog or a cat.

But how?

You see, every feature in itself can be considered as an image. Take an example of eyes. How to identify whether it is an eye? A series of strokes (resembling an oval) is what identifies it as an eye.

So, every CNN starts off by first identifying the basic features of an images, such as lines, strokes, edges and gradients. Using this information, it predicts the higher versions of features like eyes, nose, mouth, etc. Finally using these higher versions, the model identifies the image.

So far so good, right?

Now to understand how does CNN manage to obtain these basic features, first we need to understand the important aspects of an image.

Before CNN was created, researchers used to line up the pixels of an image into a single vector (like if the image is 28 X 28 then all the 784 pixels would be picked one by one and appended in a column matrix) and then pass it into a neural network. After training, the model used to predict the ‘class’ (like dog or cat) of the image. The approach was decent for simple datasets like MNIST (where you only have 10 possible outputs or 10 ‘classes’) but rapidly lost accuracy for more complex datasets.

Then it was identified that they were missing out a critical aspect of an image - Spatial arrangement of pixels. For an image prediction model, not only does the individual pixels matter but the position of each pixel relative to others is equally important. You don’t think that is important? Imagine you are having an image of a dog. If you switch the positions of a bunch of pixels, you would get an image which literally means nothing. If you observe, the pixels are same. Only their relative positions are different. Hence, relative positions are a critical aspect while determining the class of an image. When we use the standard neural network, we arrange them in a row, essentially ignoring their original positions

This is the problem that CNN solved for us.

When you input an image in CNN, it is not flattened into long vectors. Instead, the network gradually transforms it into feature maps. Some operations reduce the dimensions, but the relationships between neighbouring pixels are preserved. CNN reduces the dimensions of the image so that the number of inputs which goes inside the standard neural network for classification is the least (yeah, you heard that right. Finally it is our old friend who does the actual classification XD).


The process:

When an image is given to a CNN, the model uses a special matrix called as filter. These filters usually have a dimension of 3X3 or 5X5 and slide across the image and computes a dot product at every location. Some additional techniques, such as strides and padding, control how the filters move across the image and how much information is preserved. By repeating the convolution, the network gradually focuses on the most important patterns in the image while discarding irrelevant details (referred to as noise). The final representation is much smaller than the original image but still contains enough information for accurate classification. Also as we have technically downsampled the image, we have also managed to preserve the important spatial informations.


Yes, I understand you. You might think, what is the use? If we have to use the standard neural network anyways, why not do it using the original pixels? Well, I don’t have to answer that. If you look at the change in accuracy because of this architecture, you would understand the importance of CNN and its method of compressing information.


So this is the basic idea about CNN. I hope you got some idea about this architecture. Ask your questions in the comment.

Good luck!

Comments

Popular posts from this blog

UNIFIED QR CODE SYSTEM FOR A SEAMLESS HOTEL EXPERIENCE

MY FIRST-YEAR EXPERIENCE AT IIT-D AI HACKATHON