Mismatch of kernel size

This code work well, no problem.
However I have a question because The size of the image is not divisible by the kernel.
(Conv2d in pytorch on colab.)

The code is here https://github.com/YutaroOgawa/Qiita/blob/master/MNIST_IIC.ipynb

I could see the size,
torch.Size([512, 1, 28, 28])
This code was added by myself.
[for data, target in train_loader:

And the first conv2d layer is
self.conv1 = nn.Conv2d(1, 128, 5, 2, bias=False)

Therefore, the output pixels are calculated by
output pixel = (pixel - kernel size) / stride + 1

but (28 - 5) / 2 become odd and could not divisible.
I couldn’t understand this.

Thank you for reading.

The value is rounded as we see below:

import torch
import torch.nn as nn

input = torch.randn(512, 1, 28, 28)

conv1 = nn.Conv2d(1, 128, 5, 2, bias=False)

1 Like

Thank you so much.
I could understand.
Also, Thank you for telling sample code, it was very useful for me.

Thank you.