Change the flattening from x = x.view(-1, 16 * 5 * 5) to x = x.view(x.size(0), -1) to keep the batch size equal in case you have a miscalculation in the feature size.
If you are running into a shape mismatch error in the next linear layer, print the shape of x after the view operation and make sure the linear layer has its in_features set to the right value.