The flattening looks wrong, since you are changing the batch size. Change the arguments to start_dim=1, end_dim=-1 (or just use the default).
Alternatively, use x = x.view(x.size(0), -1) which is a bit more clear to me to see how the tensor is flattened.