Skip to content

Commit

Permalink
<Fixed a bug in accuracy calculation>
Browse files Browse the repository at this point in the history
<The variable `correct` is a tensor object, which may lead to a
RuntimeError when divided by an int. Using the method `.item()` solves
this problem. Fix yunjey#220>
  • Loading branch information
htlee6 committed Oct 20, 2020
1 parent 0500d3d commit f1cfe23
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tutorials/01-basics/logistic_regression/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
total += labels.size(0)
correct += (predicted == labels).sum()

print('Accuracy of the model on the 10000 test images: {} %'.format(100 * correct / total))
print('Accuracy of the model on the 10000 test images: {} %'.format(100 * correct.item() / total))

# Save the model checkpoint
torch.save(model.state_dict(), 'model.ckpt')

0 comments on commit f1cfe23

Please sign in to comment.