Skip to content

Commit 8894555

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 7d95eb3 + 304c0b2 commit 8894555

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

tutorial-contents-notebooks/301_regression.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
},
126126
"outputs": [],
127127
"source": [
128-
"optimizer = torch.optim.SGD(net.parameters(), lr=0.5)\n",
128+
"optimizer = torch.optim.SGD(net.parameters(), lr=0.2)\n",
129129
"loss_func = torch.nn.MSELoss() # this is for regression mean squared loss"
130130
]
131131
},
@@ -261,9 +261,9 @@
261261
" plt.cla()\n",
262262
" plt.scatter(x.data.numpy(), y.data.numpy())\n",
263263
" plt.plot(x.data.numpy(), prediction.data.numpy(), 'r-', lw=5)\n",
264-
" plt.text(0.5, 0, 'Loss=%.4f' % loss.data[0], fontdict={'size': 20, 'color': 'red'})\n",
264+
" plt.text(0.5, 0, 'Loss=%.4f' % loss.data.numpy(), fontdict={'size': 20, 'color': 'red'})\n",
265265
" plt.show()\n",
266-
" plt.pause(0.2)\n",
266+
" plt.pause(0.1)\n",
267267
"\n",
268268
"plt.ioff()\n"
269269
]

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)