Description
At the start of the tutorial:
https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html
You have 5x5 convolutions and in both of the Conv layers and then you add the next linear layer explicitly writing that it has size (16 * 5 * 5, 120). Clearly the 16 comes from the number of filters in the prev. layer, and it seems at first obvious that the hard coded 5 * 5 might come from the filter size, but it does not - it should come from the dimension of the input of the image (which is 32 x 32). You could make a note of this, or simply change the size of the filters to 3 x 3 or 7 x 7 or something.
Of course the code currently runs fine, and I see you added the nice pedagogical function def num_flat_features(self, x)
, which was what helped me realise something was amiss in the code.
Below is the init of the Net()
class which confused me for reference.
def __init__(self):
super(Net, self).__init__()
# 1 input image channel, 6 output channels, 5x5 square convolution
# kernel
self.conv1 = nn.Conv2d(1, 6, 5)
self.conv2 = nn.Conv2d(6, 16, 5)
# an affine operation: y = Wx + b
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
There is also an issue here, which is maybe related.
Apologies if this is well written, and thanks to all who made the great PyTorch intro pages.