From 0212a9d368ca68ed50deb8bcf80fc9a33221067d Mon Sep 17 00:00:00 2001 From: Jerome Date: Thu, 12 Jul 2018 17:01:31 +0800 Subject: [PATCH 1/4] Fixing error learning rate for this sample --- tutorial-contents-notebooks/301_regression.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorial-contents-notebooks/301_regression.ipynb b/tutorial-contents-notebooks/301_regression.ipynb index 8880d2c..6485fd0 100644 --- a/tutorial-contents-notebooks/301_regression.ipynb +++ b/tutorial-contents-notebooks/301_regression.ipynb @@ -125,7 +125,7 @@ }, "outputs": [], "source": [ - "optimizer = torch.optim.SGD(net.parameters(), lr=0.5)\n", + "optimizer = torch.optim.SGD(net.parameters(), lr=0.4)\n", "loss_func = torch.nn.MSELoss() # this is for regression mean squared loss" ] }, @@ -261,7 +261,7 @@ " 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.item(), fontdict={'size': 20, 'color': 'red'})\n", " plt.show()\n", " plt.pause(0.2)\n", "\n", From 840ed35b9c269a03597691519dc425cd44dfac9e Mon Sep 17 00:00:00 2001 From: Jerome Date: Thu, 12 Jul 2018 17:08:43 +0800 Subject: [PATCH 2/4] Update 301_regression.ipynb --- tutorial-contents-notebooks/301_regression.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorial-contents-notebooks/301_regression.ipynb b/tutorial-contents-notebooks/301_regression.ipynb index 6485fd0..2f7590a 100644 --- a/tutorial-contents-notebooks/301_regression.ipynb +++ b/tutorial-contents-notebooks/301_regression.ipynb @@ -125,7 +125,7 @@ }, "outputs": [], "source": [ - "optimizer = torch.optim.SGD(net.parameters(), lr=0.4)\n", + "optimizer = torch.optim.SGD(net.parameters(), lr=0.2)\n", "loss_func = torch.nn.MSELoss() # this is for regression mean squared loss" ] }, From 410f7eca889987e07427127e4d313da6522b189d Mon Sep 17 00:00:00 2001 From: Jerome Date: Thu, 12 Jul 2018 17:14:10 +0800 Subject: [PATCH 3/4] Update 301_regression.ipynb --- tutorial-contents-notebooks/301_regression.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorial-contents-notebooks/301_regression.ipynb b/tutorial-contents-notebooks/301_regression.ipynb index 2f7590a..04b9db9 100644 --- a/tutorial-contents-notebooks/301_regression.ipynb +++ b/tutorial-contents-notebooks/301_regression.ipynb @@ -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.item(), 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" ] From 99158fd0ca952f211911ca26e548e88211c9d57e Mon Sep 17 00:00:00 2001 From: Jerome Date: Sat, 14 Jul 2018 22:35:34 +0800 Subject: [PATCH 4/4] Fixing error accurate and error tensor to numpy --- tutorial-contents/502_GPU.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorial-contents/502_GPU.py b/tutorial-contents/502_GPU.py index 741587a..58cd07b 100644 --- a/tutorial-contents/502_GPU.py +++ b/tutorial-contents/502_GPU.py @@ -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])