OK, from your code before the edit it looked like you are reshaping the data.
Could you post your model definition? The error has to be there, since the other parts work with this dummy model:
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv = nn.Conv2d(3, 1, 3, 1, 1)
        self.fc1 = nn.Linear(1*32*32, 10)
        
    def forward(self, x):
        x = self.conv(x)
        x = x.view(x.size(0), -1)
        x = self.fc1(x)
        return x