DEV Community


Posted on

Convolutional Neural Networks for Image Classification

Convolutional Neural Networks (CNNs) are a type of neural network that are commonly used for image classification tasks because, unlike neural networks, they are able to classify a high number of pixels that are often found on images.

What Makes a Neural Network Convolutional?

Convolutional networks are able to identify patterns much better. The main difference that allows this is the convolutional operation that uses a filter (usually 3x3 or 5x5) that is applied to each 3x3 (or 5x5) block on the original image.

Alt Text

In the above image, we see a filter is applied to each possible block to create a new matrix.

Using Padding to Maintain Dimensions

One thing to note is that when the filter is applied, you end up with a smaller image. In the above example, you can see that a 5x5 image with a 3x3 filter results in a 3x3 image. In addition, pixels along the edges of the original image do not get applied by the filter as much as those close to the center.

One way to solve both of these issues is using padding, which is basically adding extra blank pixels around the edges of the image. This will return an image of the same size as the original image and allow the edge pixels to be filtered more.
Alt Text


Striding can also affect the output image. Basically, you are controlling how many pixels over a filter will move, which will affect the output size (higher striding yields smaller image). For example, both examples above are striding by 1 pixel while the example below strides by 2.
Alt Text

Pooling layer

Everything above is done before the fully connected neural network. The pooling layer is the last step, which basically downsizes the convolutional layers while "pooling" together all the patterns that the convolutional layers found. Typically, the Max Pooling parameter is used.

When to Bring Fully Connected Layers

After the pooling, the next steps are basically the same as building a regular fully connected neural network. Think of a CNN as preliminary prep before the fully connected layers are applied.

Discussion (0)