I was looking at the tensor shape of the following cnn:
def __init__(self):
super().__init__() # just run the init of parent class (nn.Module)
self.conv1 = nn.Conv2d(1, 32, 5)
self.conv2 = nn.Conv2d(32, 64, 5)
self.conv3 = nn.Conv2d(64, 128, 5)
def convs(self, x):
x = self.conv1(x)
x = F.relu(x)
x = F.max_pool2d(x, (2, 2))
x = self.conv2(x)
x = F.relu(x)
# torch.Size([64, 19, 19])
x = F.max_pool2d(x, (2, 2)) # torch.Size([64, 9, 9])
x = self.conv3(x)
x = F.relu(x)
#torch.Size([128, 5, 5])
x = F.max_pool2d(x, (2, 2)) # torch.Size([128, 2, 2])
I noticed that in the conv2 maxpooling we’re diving 19 by 2 = 8.5 ~ 9
but in conv3 we’re diving 5 by 2 = 2.5 ~ 2
In the first scenario we round to the upper bound and in the second case the lower bound. Can anyone explain what happenng?