3
$\begingroup$

I was looking at the equations for having this true and I believe its possible.

For simplicity everything is squared. Say we have a square image of size $n$. If we have filters of kernel size $f$ the we have a resulting feature vector of size:

$$ n - f + 1 $$

when we padd we get an image of size $n + 2p$. So we we do convolution on that we get:

$$ n+2p-f +1 $$

So what we want is:

$$ n+2p-f+1 = n$$

which results in:

$$ p = \frac{f-1}{2} $$

and use $f$ being odd (odd size filters).

Seems that as long as the padding always satisfies this no matter what deep of the network we are (e.g. middle layers vs input) we always have inputs of size $n$. Is this true? I really want my feature vectors to never downsample.

$\endgroup$

1 Answer 1

2
$\begingroup$

Yes, your reasoning is correct.

I recommend having a look at A guide to convolution arithmetic for deeplearning for a general overview of size formulas in more complicated cases like non-unit strides, dilated convolutions etc.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.