Solved by ptrblck in post #2 
              
              
                The error is raised, since the flattened activation output contains more number of features than the first linear layer (self.fc1) expects. This line of code: 
x = x.view(x.size(0), 16*5*5)

creates a tensor in the shape [batch_size, 16*5*5=400], while (based on the error message) it contains 595360 …