# How to explain the connection between the input layer and H1 of this CNN Architecture?

I am currently reading the paper proposed by LeCun et al. for handwritten zip code recognition. There is this figure below visualizing the CNN architecture. But I do not really understand how the connection between Layer H1 and input layer makes sense. If there are 12 kernels with size 5x5, shouldn't the layer H1 be 12x144? Or is there any downsampling taking place here too?

Yes, the spatial dimensions (height and width) are reduced: the input is 16x16, H1 is 8x8 and H2 is 4x4.

Also see the first paragraph in the architecture section: Source

In modern terms you would say that they use a stride of 2. Which reduces the spatial dimensions accordingly.

The formula for the spatial output dimension $$O$$ of a (square shaped) convolutional layer is the following:

$$O = \frac{I - K + 2P}S + 1$$ with $$I$$ being the input size, $$K$$ being the kernel size, $$P$$ the padding and $$S$$ the stride. Now you might think that in your example $$O = \frac{16 - 5 + 2*2}2 + 1 = 8.5$$ (assuming $$P=2$$)

But take a closer look at how it actually plays out when the 5x5 kernel of layer H1 scans the 16x16 input image with a stride of 2:

As you can see from the light grey area the required and effective padding is actually not 2 on all sides. Instead for the width or height respectively it is 2 on one side and 1 on the other side, i.e. on average $$(2+1)/2=1.5$$.

And if you plug that into the equation to calculate the output size it gives: $$O = \frac{16 - 5 + 2*1.5}2 + 1 = 8$$. Accordingly the convolutional layer H1 will have spatial dimensions of 8x8.

• Hi thanks for the reply! But the formula for output size calculation is: O=(input_size - filter_size)/stride + 1, right? in this case, the equation would be (16-5)/2 + 1 = 6,5, and not 8 :/ – user77241 Jan 2 '20 at 12:55
• @EnyangWang That is the usual headache with this formula (tho you entirely skipped the padding). I have added an explanation. Hope it helps. – Sammy Jan 2 '20 at 14:40
• hi, thanks for the further explanation! it seems to make sense, i just didnt read in the paper that they had applied padding, that is why i took out the padding from the equation :) thanks a lot, much appreciated! :) – user77241 Jan 5 '20 at 22:41