Based on the error message the input to the conv layer has 3 channels (I guess it could be the image tensor) while the conv layer expects an input with a single input channel. You could change in_channels to 3 in: nn.Conv2d(3, 64, 3, 1) to fix this.