This error is raised in self.fc1, which expects 16*28*28=12544 input features, while the input activation x is flattened to [1, 1065360] in x=x.view(x.size(0), -1).
You could either change the in_feautres of self.fc1 to 1065360 or make sure the input tensor has such a spatial size that the flattened activation has 12544 features.