# Question about convolutional layer output size calculation

When I tried to estimate the output size of conv layer using the formula in the doc,

the number I got from the formula is actually different from what I get from the layer.

for the 2d input of size (101, 40)
with kernel(16,8), stride (2,1) padding (0,0), dilation (1,1),
torch.2dconv generates (43,33)
while formula seems to give (44,33)

where is this mismatch coming from?

Also I tried to understand the formula but couldn’t figure out where the last -1 operation comes from.
we should be following basic math ordering (Brackets, Orders, Division and Multiplication, and Addition and Subtraction) here right?

Can anyone clarify?

`Hout = (101 +2*0 - 1*(16-1) -1)/2 +1` gives me 43

opps thanks, I actually for got to add -1 at the end.
But still… can you explain why we need the last -1?

I actually found out why I got so confused.

without dilation,
out = (in + 2*p - k)/s + 1

however, with dilation new kernel size k_d = d * (k-1) + 1,
Plugging this back into the above formula we have

out = (in + 2p - k_d)/s + 1
= (in + 2
p - (d * (k-1) + 1))/s + 1
= (in + 2*p - d * (k-1) - 1)/s + 1

same as the one from doc.