Solved – How to handle even and odd convolutional filter sizes and images

conv-neural-networkconvolutionneural networks

Is there a rule of thumb for determining the size of a convolutional filter given the shape of the input? Specifically, if you want to do a 1D convolution over an even-length vector, does the kernel need to be a divisor of the vector length? Does the kernel need to be even? I understand that when using an odd-length kernel, you align the center element with the stride position on the input vector, but with even-length kernels there is no center position. For example, if I have a vector [a,b,c,d] and a kernel [0,1], should the kernel start by aligning 1 with a or should 0 align with a?
Also is there any theory on why and how much padding and stride you should use when convolving and trade-offs between these two parameters?

Best Answer

It's usual to use stride 1 and pad the input layers such that the output layers so that they are the same size as the input layers. Using stride lengths of 1 separates the processes of feature extraction (the job of the convolutional layers) and making the model invariant to spatial translation (the job of the pooling layers). Padding the input layers ensures that the model doesn't slowly lose information about edge elements.