0
$\begingroup$

I am trying to understand the ResNet dimensions, but got stuck at the first layer. We are passing a [224x224x3] image into 64 filters with kernel size 7x7 and stride=2. According to the ResNet source code from pytorch we are also using zero padding of size 3. The output size should be 112, but I get a output size of 112.5. To get an output size of 112 we need padding of 2.5.. See:

enter image description here

I do not understand how the output of 112 is created. Is the padding adjusted by pytorch automatically to match floor (output)?

$\endgroup$

1 Answer 1

0
$\begingroup$

As you can see in the pytorch documentation for torch.nn.Conv2d, the output size of a 2d convolutional layer can be calculated that is very similar to the formula you show:

$$ H_{out} / W_{out} = \lfloor \frac{H_{in} + 2 * padding - dilation * (kernel\_size - 1) - 1}{stride} + 1 \rfloor $$

So after performing the calculations pytorch indeed floors the output to get the largest integer smaller than or equal to the calculated output since half pixels do not exist.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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