Stride and padding mode in convolution

The convolution kernel convolves around the input volume by shifting one column/row at a time. The amount by which the filter shifts is called the stride. In the preceding scenario, the stride was implicitly set to 1. If we shift the kernel by a stride of 2 (two columns or two rows), the number of output units shrinks:

The convolution operator reduces the size of the input. If we want to preserve the size of the input, we need to pad zeros evenly around the input. For a two-dimensional image, this means adding a border of zero pixels around the four sides of the image. The thickness of the border—that is, the number of rows of pixels added—depends on the kernel size being applied. Any convolution operator implementation typically takes a mode argument that specifies the padding type. There are two such arguments:

  • SAME: Specifies that the output size is to be the same as the input size. This requires the filter window to slip outside the input map, hence the need for padding.
  • VALID: Specifies that the filter window stays at a valid position inside the input map, so the output size shrinks by filter_size minus one. No padding occurs.

In the preceding one-dimensional convolution code, we have set the mode as VALID, and thus no padding occurs. You may try with same padding.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.118.171