Path: blob/master/Applied Generative AI with GANS/8 CNN_Mathematical_Explanation.ipynb
4780 views
Kernel: Python 3 (ipykernel)
Convolutional Neural Networks (CNN)
Step-by-Step Mathematical Explanation
This notebook explains CNNs with mathematical intuition and simple examples.
1. What is a Convolution?
A convolution is a mathematical operation between an input matrix (image) and a kernel (filter).
Formula: 
2. Example Input Image and Kernel
We use a 3×3 image and a 2×2 kernel to explain convolution.
In [1]:
Out[1]:
(array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]),
array([[ 1, 0],
[ 0, -1]]))
3. Convolution Calculation (Manually)
Each output value is computed by element-wise multiplication followed by summation.
In [2]:
Out[2]:
array([[-4., -4.],
[-4., -4.]])
In [ ]:
4. Activation Function (ReLU)
ReLU introduces non-linearity.

In [3]:
Out[3]:
array([[0., 0.],
[0., 0.]])
In [ ]:
5. Pooling (Max Pooling)
Pooling reduces spatial dimensions.

In [5]:
Out[5]:
89
In [ ]:
6. Fully Connected Layer (Mathematics)
Flatten the feature map and apply:

Where:C = number of classes
In [ ]:
7. Summary
Convolution extracts features
ReLU adds non-linearity
Pooling reduces size
Fully connected layers perform classification
A CNN learns convolutional filters that extract hierarchical spatial features and optimizes them end-to-end using backpropagation to minimize classification loss.



In [ ]: