The number of input features for vgg16 is 25088, but besides that the code looks alright.
EDIT:
Sorry, missed an issue.
Since you are using nn.LogSoftmax as the last activation function, you should use nn.NLLLoss as your criterion.
Alternatively you could remove the nn.LogSoftmax and use nn.CrossEntropyLoss, which will internally use F.log_softmax and nn.NLLLoss.