# Convolution
Convolution is a mathematical operation of two matrices where the second matrix is overlaid on top of the first, an element wise product of the two matrices is taken and the result is summed to populate one element of the resultant matrix. The second matrix is slid over the first to fill the matrix
![[Pasted image 20210105231922.png]]
The second matrices are called filters. Here are some filters
**Sobel Filter**:
| 1 | 0 | 1 |
| --- | --- | --- |
| 2 | 0 | -2 |
| 1 | 0 | -1 |
x
**Scharr Filter**:
| 3 | 0 | -3 |
| --- | --- | --- |
| 10 | 0 | -10 |
| 3 | 0 | -3 |
Here are more fun filters https://lodev.org/cgtutor/filtering.html
## Padding
Padding is the process of adding zeros around the matrix
![[Pasted image 20210105232439.png]]
**Valid Convolution** - means no padding
**Same Convolution** - means add padding such that the resultant matrix is same size as input matrix
## Channels
The number of "channels" in a filter or "depth" of a filter is always same as the depth of the input
![[Pasted image 20210105232830.png]]
## Multiple Filters
Multiple filters are applied on the same input and the results are stacked on top of each other
![[Pasted image 20210105232946.png]]
## Stride
Stride is the number of rows/columns to offset by when siding the filter over the matrix.
## Notation:
$n_{H/W}^{[l]} = \frac{n_{H/W}^{[l-1]} + 2p^{[l]} - f^{[l]}}{s^{[l]}}+1$
where,
$n_{H/W}^{[l]}$ is height or width of new layer
$n_{H/W}^{[l-1]}$ is height or width of previous layer
$p$ is the number of padding
$f$ is filter size
$s$ is the stride
## ![[Pooling]]
## 1x1 Convolution
1x1 convolutions are an effective technique to reduce the depth of a layer without affecting its height or width. It is used widely in the "Inception" network