I’m new to Pytorch, and I’m solving an image classification problem. I’ve built a ResNet (as opposed to loading it from Pytorch hub because I wanted to learn how they work). Here’s the code. The relevant functions begin at line #257.
One of the convolutional layers has the wrong number of input channels, and I’m struggling to locate the exact source of the problem.
The error reads:
Given groups=1, weight of size [128, 64, 1, 1], expected input[20, 128, 45, 45] to have 64 channels, but got 128 channels instead
I realise that many similar questions have been asked, and I’ve tried to implement relevant answers to those questions to no avail.
When I run into these I normally add a print(x.shape) after line 281 and see which ConvBlock call is initiating the error. It’s a good starting point. Break the after the first few prints.
Thanks for the tip. In addition to printing x.shape, I decided to print self.conv, which is the nn.Sequential object that corresponds to that layer’s contents. Things broke down when the model arrived at the following: