Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chao1224 committed Jul 6, 2017
1 parent 3aca2d7 commit 3b60784
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions mnist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ def test():
data, target = Variable(data, volatile=True), Variable(target)
current_batch_size = data.data.size()[0]
output = model(data)
# F.nll_loss is averaged among each batch
test_loss += F.nll_loss(output, target).data[0] * current_batch_size
test_loss += F.nll_loss(output, target).data[0] * current_batch_size # sum up batch loss
pred = output.data.max(1)[1] # get the index of the max log-probability
correct += pred.eq(target.data).cpu().sum()

test_loss = test_loss # sum of loss function
test_loss = test_loss # sum of loss function over all data points
test_loss /= len(test_loader.dataset)
print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format(
test_loss, correct, len(test_loader.dataset),
Expand Down

0 comments on commit 3b60784

Please sign in to comment.