From 9fb0f5b6c68166b4000aeffaf30ae0bc5e3e8f15 Mon Sep 17 00:00:00 2001 From: howtocodewang Date: Wed, 24 May 2017 08:59:21 +0800 Subject: [PATCH] Update 502_GPU.py There are several little mistakes in this file which will make you fail to debug successfully. --- tutorial-contents/502_GPU.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tutorial-contents/502_GPU.py b/tutorial-contents/502_GPU.py index e4c3ec6..9403ab3 100644 --- a/tutorial-contents/502_GPU.py +++ b/tutorial-contents/502_GPU.py @@ -26,7 +26,7 @@ test_data = torchvision.datasets.MNIST(root='./mnist/', train=False) # !!!!!!!! Change in here !!!!!!!!! # test_x = Variable(torch.unsqueeze(test_data.test_data, dim=1)).type(torch.FloatTensor)[:2000].cuda()/255. # Tensor on GPU -test_y = test_data.test_labels[:2000] +test_y = test_data.test_labels[:2000].cuda() class CNN(nn.Module): @@ -69,7 +69,7 @@ for epoch in range(EPOCH): test_output = cnn(test_x) # !!!!!!!! Change in here !!!!!!!!! # - pred_y = torch.max(test_output, 1)[1].cup().data.squeeze() # Move to CPU + pred_y = torch.max(test_output, 1)[1].cuda().data.squeeze() # Move to CPU accuracy = sum(pred_y == test_y) / test_y.size(0) print('Epoch: ', epoch, '| train loss: %.4f' % loss.data[0], '| test accuracy: %.2f' % accuracy) @@ -78,7 +78,7 @@ for epoch in range(EPOCH): test_output = cnn(test_x[:10]) # !!!!!!!! Change in here !!!!!!!!! # -pred_y = torch.max(test_output, 1)[1].cup().data.numpy().squeeze() # Move to CPU +pred_y = torch.max(test_output, 1)[1].cuda().data.squeeze() # Move to CPU print(pred_y, 'prediction number') -print(test_y[:10].numpy(), 'real number') +print(test_y[:10], 'real number')