top of page

Convolutional Neural Networks

Nov 23, 2022
4 min read

Convolutional Neural Networks Preview

In the previous blog we discussed Feed Forward Neural Networks. This model architecture is useful in solving logistic regression problems. When working with images for data we find that Feed Forward architecture alone does not provide results that we are happy with. Which leads this blog to Convolutional Neural Networks. I will discuss Convolutional Neural Network's with the following questions. What is it? What are the advantages? When/Where can we apply this model architecture? How does it work? How does it compare to Feed Forward NN?


What is a Convolutional Neural Network?

A Convolutional Neural Network, or CNN for short, is a neural network architecture that learns from the data itself opposed to the loss of randomly making predictions from data. Loss is still involved however it encompasses a "Convolution" algorithm that allows it to extract features and patterns from 2 dimensional inputs.


What are the advantages to a CNN?

Its advantages are the decreased amount of parameters which requires less space. The CNN also requires less power and time to train the model due to its nature of shrinking outputs/ inputs as data moves through the model. This makes the forward and backward pathway much more efficient. Features learned by a kernel on one part of an image can be used to detect features in other images. Meaning these models are much more resourceful.


When can we use a CNN?

Due to the convolution algorithm which I will discuss in another section. This can only be used on input that is 2 dimensional or larger. This makes it especially applicable to use on image classification since images are represented as matrices of pixels. It can be used on 3 color channel images as well since those are represented by 3 matrices of RGB intensity pixels. Some real world applications are:

Medical Imaging

Audio Processing

Object Detection


How does it work?

Convolutional neural networks rely on convolution. An applicable definition I found is this: "a form or shape that is folded in curved or tortuous windings". This is because as data moves through a CNN the shape and size of the matrix are constantly being changed until you reach the end of it. At the end you are left with a much smaller matrix which can be flattened into a vector. Along the way there are different layers we will discuss that change the height and change the width of the data. There are two layers that are alternating which are a Convolutional layer and a Pooling layer.



Convolutional Layer

The convolutional layer can be visualized above. You start with a kernel which is usually 3x3 and in the gif above is represented by the "Convolved Feature". It slides over a 2d input which is larger than 3 by 3 and computes elementwise multiplication and adds up all the multiplied elements computed at each index of the kernel over the input. This is different from matrix multiplication because for matrix multiplication we know that you multiply the rows of your first matrix by the columns of your second matrix. For that to happen the rows and the columns need to be of equal size and at that you are still yielded a matrix or a vector. Here we are computing elements for each index of our kernel. It will stride from left to right until it has covered the whole input layer. Stride is simply how many elements it moves over after each multiplication is done. Stride is specified by the ML Practitioner. In the above example stride is 1 because after each multiplication is done it moves over 1 to the right. Something else to consider that this gif doesn't display is padding. Padding is a blank layer around the image that allows our kernel to sweep over certain elements more than once. This additional iteration over the edge elements allows the kernel to get more exposure to certain features. The output of a convolution is referred to as a "Feature Map".


Pooling Layer

There are two common types of pooling layers. Average pooling and Max pooling. Conceptually average pooling will represent the average event of a feature occurring and max pooling will represent the maximum amount of events that a feature occurs. We will discuss max pooling. Max pooling will essentially take input from a Convolutional layer and transform the dimensions. In a CNN you are doing a number of convolutions and pooling's until you are left with a much smaller feature map than you started with. The output of the model will look at each feature and predict what class the input belongs to from that feature.


How does CNN Compare to Feed Forward NN?

Feed forward neural network's add a hidden layer. From this hidden layer, and non linear activation that would allow our model to learn more complex relationships. With CNN we are adding a lot more complexity to how the data is manipulated. This added manipulation allows for our model to now be able to detect "features". This gives us a much more powerful and useful tool to use for image processing. Feed Forward NN's are not exclusively for image processing as they can be used on numerical and categorical data. It can also be used with images however it is not nearly as powerful for this application. CNN allows us to have a much more specialized architecture for handling images as data.


Summary

Convolutional Neural Networks are an extremely useful and powerful tool to use with image processing. We learned that they are only applicable to 2 dimensional data which can be images or audio. They work through a combination of Convolution and Pooling layers which manipulates our input data until we get it down to an extracted "feature". The advantages to this were the decreased space and time requirements. Additionally the added feature and layer sharing allowed our models to identify future images with features it had already extracted from previous epochs. This feature extraction means that it actually learns directly from the input data opposed to just guessing, looking at its loss and determining it was wrong and improving its future guesses. CNN's won't quite get you state of the art models for every problem you apply them to so in the next blog we will look at Residual Neural Networks.


Sources:


 
 
 

Comments


bottom of page