Why do convolutional filters use odd parity?
In deep learning models, convolutional filters are usually used to extract spatial features from the data. The use of odd-sized convolutional filters is common in these models. Most of the state-of-the-art architecture goes with this convention. In this answer, we will dive into the “why” of this convention.
What is a convolution operation in deep learning?
In deep learning, a convolution operation is used to encode the information of the input matrix in terms of filters or kernels. The mathematics behind the operation is simple. That is, a convolutional filter is multiplied by the input matrix element-wise. The following figure highlights the working of the convolution operation.
The same operation can be extended to a larger input matrix. In that case, however, the convolution operation can not be applied at once. The alternative is to apply the convolutional filter in a series of windows.
What should be the parity of the convolutional filter?
We have briefly discussed the convolution operation and how it can be applied to matrices of different sizes. Now, we will talk about determining the
Simplicity: The use of padding is very common in deep learning architectures. When adding
padding to the input matrix, we want the resulting matrix to be in the shape. The odd-sized convolutional filters keep the mathematics simple. The following is an equation for calculating the resulting size of a convolution operation:
Assuming that
From the above equation, we can see how using even-sized filters will result in decimal padding sizes, therefore, causing aliasing errors. The code below can be used to test this.
# filter size is even.filter_size = 6padding_size = (filter_size-1)/2.0print("Padding Size : " + str(padding_size))
Note: To get a better idea of padding, check out another Educative Answer on subsequent convolution layers.
Symmetry: In odd-sized filters, the matrices are symmetrically shaped, and therefore, each filter can be centered around an anchor point.
Conclusion
The use of odd-sized convolutional filters helps keep the padding simple and gives the output a symmetrical shape.
Free Resources