test_loss = 0
correct = 0
for data, target in test_loader:
if args.cuda:
data, target = data.cuda(), target.cuda()
data, target = Variable(data, volatile=True), Variable(target)
output = model(data)
test_loss += F.nll_loss(output, target, size_average=False).data[0] // sum up batch loss
pred = output.data.max(1, keepdim=True)[1] // get the index of the max log-probability
After Change
for data, target in test_loader:
data, target = data.to(device), target.to(device)
output = model(data)
test_loss += F.nll_loss(output, target, size_average=False).item() // sum up batch loss
pred = output.max(1, keepdim=True)[1] // get the index of the max log-probability
correct += pred.eq(target.view_as(pred)).sum().item()