1 of 13

Convolution Neural Network

2 of 13

INTRODUCTION

A Convolutional Neural Network (CNN) is a type of Deep Learning Neural architecture commonly used in Computer Vision. Computer vision is a field of Artificial Intelligence that enables a computer to understand and interpret the image or visual data.

3 of 13

KEY COMPONENTS OF A CNN

The convolutional neural network is made of four main parts.

    • Convolutional layers
    • Rectified Linear Unit (ReLU for short)
    • Pooling layers
    • Fully connected layers

4 of 13

CONVOLUTION LAYERS

This is the first building block of a CNN. As the name suggests, the main mathematical task performed is called convolution, which is the application of a sliding window function to a matrix of pixels representing an image. The sliding function applied to the matrix is called kernel or filter, and both can be used interchangeably.

Let’s consider this 32x32 grayscale image of a handwritten digit. The values in the matrix are given. Also, let’s consider the kernel used for the convolution. It is a matrix with a dimension of 3x3. The weights of each element of the kernel is represented in the grid. Zero weights are represented in the black grids and ones in the white grid.

5 of 13

STRIDE

If stride = 1, the filter will move one pixel

If stride = 2, the filter will move two pixels.

Stride is how far the filter moves in every step along one direction. we define how far the filter moves from one position to the next position by “stride”. Let’s look at an example. The red square is a filter. The computer is going to use this filter to scan the image. The output shape formula with strides is:

Output shape = ((n + 2p — f) / s + 1) x ((n + 2p — f) / s + 1) Where s is the stride value.

PADDING

Padding involves adding extra pixel rows/columns around the borders of an input image.

In the example above, the 5x5 image is padded to 7x7 by adding a single pixel row/column boundary with values of zero. This is called zero padding .

The formula for calculating output shape after padding is:

Output shape = (n + 2p — f + 1) x (n + 2p — f + 1) Where n is input size, f is filter size, and p is the padding amount.

6 of 13

ACTIVATION FUNCTIONS

In Convolutional Neural Networks (CNNs), the activation function is a critical component that introduces non-linearity into the network and helps it learn complex patterns in the input data. The activation function is applied to the output of each convolutional or fully connected layer in the CNN.

ReLU (Rectified Linear Unit):

      • The ReLU activation function is the most commonly used activation function in CNNs.
      • It applies the function f(x) = max(0, x), which means it sets all negative values to 0 and passes positive values as is.
      • ReLU is simple to compute, helps with the problem of vanishing gradients, and often leads to faster convergence during training.

7 of 13

Pooling is a fundamental operation in Convolutional Neural Networks (CNNs) that plays a crucial role in downsampling feature maps while retaining important information. In a Convolutional Neural Network (CNN), pooling layers serve the purpose of reducing spatial dimensions of the input data while retaining the most important features. This is achieved through down-sampling techniques such as max pooling or average pooling. Pooling layers help in:

·Reducing the number of parameters and computations

·Increasing the robustness to small translations and distortions

·Capturing more abstract and invariant features

·Improving the network's ability to handle larger images and spatial hierarchies

By doing so, pooling layers enable CNNs to learn more complex and robust representations of the input data.

POOLING

8 of 13

In Convolutional Neural Networks (CNNs), the flatten layer transforms the multi-dimensional output from convolutional and pooling layers into a one-dimensional vector, preparing it for input into fully connected (dense) layers.

Example:

A 3x3x1 tensor (from convolutional/pooling layers) would be flattened into a vector of size 9 (3 * 3 * 1).

FLATTENING

9 of 13

Fully Connected (FC) layers, also known as dense layers, are a crucial component of neural networks, especially in the realms of deep learning. These layers are termed "fully connected" because each neuron in one layer is connected to every neuron in the preceding layer, creating a highly interconnected network.Key Components of Fully Connected Layers are Neurons, Weights, Biases and activation function.

FULLY CONNECTED LAYERS

10 of 13

If you have 10 filters that are 3 x 3 x 3 in one layer of a neural network, how many parameters does that layer have?

Filter size: 3 x 3 x 3

Number of values per filter: 3 * 3 * 3 = 27

Number of filters: 10

Total parameters for the filters: 27 * 10 = 270

Bias term: Each filter has one bias term, so there are 10 biases.

Total parameters: 270 (weights) + 10 (biases) = 280

Therefore, the layer has 280 parameters.

11 of 13

APPLICATIONS OF CNNS

12 of 13

REFERENCE

13 of 13