Skip to content
Advertisement

RuntimeError: Given groups=1, weight of size [32, 16, 5, 5], expected input[16, 3, 448, 448] to have 16 channels, but got 3 channels instead

I am getting the following error and can’t figure out why. I printed the input size of my torch before it gets fed to the CNN:

JavaScript

Here is my error message:

JavaScript

I defined a CNN with 5 convolutional layers and two fully connected layers. I am feeding in batches of 16 and have resized the images to be (448×448). The images are colour, so I assumed an input of torch.Size([16, 3, 448, 448]) would be correct. Do I need to rearrange my tensor to be torch.Size([3, 448, 448, 16])? Just guessing here as I am fairly new to coding. I have looked online but haven’t been able to figure it out. Any help would be greatly appreciated.

JavaScript

Advertisement

Answer

You haven’t passed your output to the next layer’s input, you’re continually using the input. You should change your forward call to:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement