From 7411f602fb7786eb6551952547ac0e0436437068 Mon Sep 17 00:00:00 2001 From: keineahnung2345 Date: Tue, 13 Nov 2018 09:13:44 +0800 Subject: [PATCH] 402 - remove squeeze for 1-D array --- tutorial-contents/402_RNN_classifier.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorial-contents/402_RNN_classifier.py b/tutorial-contents/402_RNN_classifier.py index 9ef11f7..3bb8231 100644 --- a/tutorial-contents/402_RNN_classifier.py +++ b/tutorial-contents/402_RNN_classifier.py @@ -47,7 +47,7 @@ train_loader = torch.utils.data.DataLoader(dataset=train_data, batch_size=BATCH_ # convert test data into Variable, pick 2000 samples to speed up testing test_data = dsets.MNIST(root='./mnist/', train=False, transform=transforms.ToTensor()) test_x = test_data.test_data.type(torch.FloatTensor)[:2000]/255. # shape (2000, 28, 28) value in range(0,1) -test_y = test_data.test_labels.numpy().squeeze()[:2000] # covert to numpy array +test_y = test_data.test_labels.numpy()[:2000] # covert to numpy array class RNN(nn.Module): @@ -94,13 +94,13 @@ 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() + pred_y = torch.max(test_output, 1)[1].data.numpy() 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 test_output = rnn(test_x[:10].view(-1, 28, 28)) -pred_y = torch.max(test_output, 1)[1].data.numpy().squeeze() +pred_y = torch.max(test_output, 1)[1].data.numpy() print(pred_y, 'prediction number') print(test_y[:10], 'real number')