Merge pull request #60 from keineahnung2345/402-squeeze
402 - remove squeeze for 1-D array
This commit is contained in:
@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user