Merge remote-tracking branch 'origin/master'

This commit is contained in:
morvanzhou
2018-08-06 19:25:14 +08:00
2 changed files with 5 additions and 5 deletions

View File

@ -125,7 +125,7 @@
},
"outputs": [],
"source": [
"optimizer = torch.optim.SGD(net.parameters(), lr=0.5)\n",
"optimizer = torch.optim.SGD(net.parameters(), lr=0.2)\n",
"loss_func = torch.nn.MSELoss() # this is for regression mean squared loss"
]
},
@ -261,9 +261,9 @@
" plt.cla()\n",
" plt.scatter(x.data.numpy(), y.data.numpy())\n",
" plt.plot(x.data.numpy(), prediction.data.numpy(), 'r-', lw=5)\n",
" plt.text(0.5, 0, 'Loss=%.4f' % loss.data[0], fontdict={'size': 20, 'color': 'red'})\n",
" plt.text(0.5, 0, 'Loss=%.4f' % loss.data.numpy(), fontdict={'size': 20, 'color': 'red'})\n",
" plt.show()\n",
" plt.pause(0.2)\n",
" plt.pause(0.1)\n",
"\n",
"plt.ioff()\n"
]

View File

@ -70,8 +70,8 @@ for epoch in range(EPOCH):
# !!!!!!!! Change in here !!!!!!!!! #
pred_y = torch.max(test_output, 1)[1].cuda().data.squeeze() # move the computation in GPU
accuracy = torch.sum(pred_y == test_y) / test_y.size(0)
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data.numpy(), '| test accuracy: %.2f' % accuracy)
accuracy = torch.sum(pred_y == test_y).type(torch.FloatTensor) / test_y.size(0)
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data.cpu().numpy(), '| test accuracy: %.2f' % accuracy)
test_output = cnn(test_x[:10])