Keras has two border_mode for convolution2D, same and valid. Could anyone explain what "same" does or point out some documentation? I could not find any document on the net (except people asking that it be implemented in theano as well).
1 Answer
With border mode "valid" you get an output that is smaller than the input because the convolution is only computed where the input and the filter fully overlap.
With border mode "same" you get an output that is the "same" size as the input. That means that the filter has to go outside the bounds of the input by "filter size / 2" - the area outside of the input is normally padded with zeros.
Note that some libraries also support the border mode "full" where the filter goes even further outside the bounds of the input - up to "filter size - 1". This results in an output shape larger than the input.
There's a short explanation in.. numpy's convolve documentation:
http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.convolve.html
-
$\begingroup$ I know that with valid you get a smaller output. This is the kind of convolution I am used to, where you get a smaller output since the filter moves across the original image. You are saying that with "same" you go you of the original image to get the same size. What are the input for those points then, do we assume they are zero? $\endgroup$– userMay 19, 2016 at 8:47
-
1$\begingroup$ Yes, see above - "the area outside of the input is normally padded with zeros". Some libraries allow you to specify which value should be used for padding. Keras uses zeros. $\endgroup$– stmaxMay 19, 2016 at 10:10