Learn Python
Learn Data Structure & Algorithm
Learn Numpy
Learn Pandas
Learn Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Introduction
Setup
ANN
Working process ANN
Propagation
Bias parameter
Activation function
Loss function
Overfitting and Underfitting
Optimization function
Chain rule
Minima
Gradient problem
Weight initialization
Dropout
ANN Regression Exercise
ANN Classification Exercise
Hyper parameter tuning
CNN
CNN basics
Convolution
Padding
Pooling
Data argumentation
Flattening
Create Custom Dataset
Binary Classification Exercise
Multiclass Classification Exercise
Transfer learning
Transfer model Basic template
RNN
How RNN works
LSTM
Bidirectional RNN
Sequence to sequence
Attention model
Transformer model
Bag of words
Tokenization & Stop words
Stemming & Lemmatization
TF-IDF
N-Gram
Word embedding
Normalization
Pos tagging
Parser
semantic analysis
Regular expression
Learn MySQL
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
Suppose we have a grayscale image. It means we have only one layer and we convert the pixel values into 0 and 1 by using a min-max scaler. Here 0 means white color and 1 means black color. Now we know that in the human brain we have a visual cortex which is responsible for various types of image or video-related operations and we also know that there are layers and each layer is doing different types of operations like edge detection, corner detection, etc. We can also say these layers as filters. We will use filters in CNN which also works like the layers of the visual cortex. There are too many filters. Different filters are used for different works.
Suppose we have a 6x6 Gary image and a 3x3 filter. This filter is used for edge detection. CNN will do some
mathematical operation on our image and will find the vertical edge of our image.
Our image layer:
0 | 0 | 0 | 1 | 1 | 1 |
---|---|---|---|---|---|
0 | 0 | 0 | 0 | 1 | 1 |
0 | 0 | 0 | 1 | 1 | 1 |
0 | 0 | 0 | 1 | 1 | 1 |
0 | 0 | 0 | 1 | 1 | 1 |
0 | 0 | 0 | 1 | 1 | 1 |
Our filter is:
1 | 0 | -1 |
---|---|---|
2 | 0 | -2 |
1 | 0 | -1 |
Now, at first, put the filter first row, and the first column on the image layer first-row and first column,
and other rows and columns of the filter will get automatically set to the rows and columns of the image layer
in order.
The new image layer matrix after calculations:
0 | -4 | -4 | 0 |
---|---|---|---|
0 | -4 | -4 | 0 |
0 | -4 | -4 | 0 |
0 | -4 | -4 | 0 |
How we get this layer?
As we know that we put our filter on the image layer. So at first, we put filter first-row and first-column on
image layer first row and first column and other rows and column will automatically get set in order. Now
after putting the filter on the image layer we have to multiply each filter cell value with the image layer
cell value and then we have to do the summation.
So here = first-row and first-column value of the filter is 1 and image layer is 0, so the result of
multiplying is =0.
Then the result of the first-row and the second-column of the filter and image layer is = 0*0=0.
Now the first-row third-column=0*(-1)=0
Then second-row first-column=2*0=0
Then we will calculate second-row second column , then second-row third-column, then third-row first-column,
third-row second-column, and third-row third-column and then we will do summation of all the result.
Summation=0+0+0+0+0+0+0+0+0=0
Now we have to put this value on our new layer matrix first-row first-column. Now go to the new layer matrix
and you will see that the value of the first-row and first-column is 0. After calculating we have to move the
filter to one column right and apply the filter again.
Summation result=0+0+0+0+0+0+(-1)+(-2)+(-1)=-4
.Now we have put this value on the first-row and second-column cell of the new layer. Now go to the first-row
and second-column of the new layer matrix and you will see -4 is written. Then we have to move our filter one
step right or one column right. It means now our filter first-row and the first-column will be set on the
image layer first-row third-column and again we have to do the calculation. After the calculation we have to
put the value again to the new image layer then have to move our filter again one step right or one column
right. We have to move the filter to one step right until the columns get the end. After the columns get the
end, we have to come one step down. It means now we have to put our filter on the second-row first-column then
again have to do the calculation and again have to move one step right after calculation.
This process will go on until the total rows and columns end and after each calculation, we have to put values
in our new image layer. This way we run our convolution operation.
Now we can see that our new image matrix max value is 0 and min value is -4. After this, we can say that our
new image layer matrix is 4x4 but our main image matrix is 6x6. This means that we have lost some information
from our image. So we can say that after convolution we lose some information.