update accuracy function

This commit is contained in:
morvanzhou
2018-06-29 10:09:52 +08:00
parent 79380fb90e
commit f2ebd8a37b
3 changed files with 4 additions and 4 deletions

View File

@ -95,7 +95,7 @@ for epoch in range(EPOCH):
if step % 50 == 0:
test_output = rnn(test_x) # (samples, time_step, input_size)
pred_y = torch.max(test_output, 1)[1].data.numpy().squeeze()
accuracy = float(sum(pred_y == test_y)) / float(test_y.size)
accuracy = float((pred_y == test_y).astype(int).sum()) / float(test_y.size)
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data.numpy(), '| test accuracy: %.2f' % accuracy)
# print 10 predictions from test data