Skip to content

Commit f1cfe23

Browse files
committed
<Fixed a bug in accuracy calculation>
<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>
1 parent 0500d3d commit f1cfe23

File tree

1 file changed

+1
-1
lines changed
  • tutorials/01-basics/logistic_regression

1 file changed

+1
-1
lines changed

tutorials/01-basics/logistic_regression/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
total += labels.size(0)
7171
correct += (predicted == labels).sum()
7272

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

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

0 commit comments

Comments
 (0)