How can I calculate the acuracy for  the current mini batch in my training? My trainining code is just:
for epoch in range(args.epochs):
  for i, (images, captions, lengths) in enumerate(train_loader):
    targets = pack_padded_sequence(captions, lengths, batch_first=True)[0]
    features = encoder(images)
    outputs = decoder(features, captions, lengths)
    loss = criterion(outputs, targets)

how can I get how many are correct from that code?
I tried several ways but cant get it to work:
correct = (targets.eq(outputs)).sum()
Im sure there should be a generic way to do this. if criterion can calculate the loss without knowing the shapes, I think I should be able to calculate accuracy as well? Any idea on how to do this?
File “train.py 43”, line 182, in 
main(args)
File “train.py 43”, line 139, in main
correct = (ttargets.eq(toutputs)).sum()
File “/home/joy/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py”, line 710, in eq
return Eq()(self, other)
File “/home/joy/anaconda3/lib/python3.6/site-packages/torch/autograd/_functions/compare.py”, line 14, in forward
mask = getattr(tensor1, self.fn_name)(other)
TypeError: eq received an invalid combination of arguments - got (torch.cuda.FloatTensor), but expected one of:

(int value)
didn’t match because some of the arguments have invalid types: (torch.cuda.FloatTensor)
(torch.cuda.LongTensor other)
didn’t match because some of the arguments have invalid types: (torch.cuda.FloatTensor)