Skip to content

Commit 99158fd

Browse files
authored
Fixing error accurate and error tensor to numpy
1 parent d053113 commit 99158fd

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

tutorial-contents/502_GPU.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def forward(self, x):
7070
# !!!!!!!! Change in here !!!!!!!!! #
7171
pred_y = torch.max(test_output, 1)[1].cuda().data.squeeze() # move the computation in GPU
7272

73-
accuracy = torch.sum(pred_y == test_y) / test_y.size(0)
74-
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data.numpy(), '| test accuracy: %.2f' % accuracy)
73+
accuracy = torch.sum(pred_y == test_y).type(torch.FloatTensor) / test_y.size(0)
74+
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data.cpu().numpy(), '| test accuracy: %.2f' % accuracy)
7575

7676

7777
test_output = cnn(test_x[:10])

0 commit comments

Comments
 (0)