From 317203c1f0c64198f0244afceb22d82ad60c54e2 Mon Sep 17 00:00:00 2001 From: Nadim Kawwa <40652202+NadimKawwa@users.noreply.github.com> Date: Fri, 16 Nov 2018 18:19:21 -0800 Subject: [PATCH] Code optimization In the block above we are appending to train_losses and test_losses. Instead of computing the values again, it might be more efficient to retrieve the most recently added values in the array. --- .../Part 5 - Inference and Validation (Solution).ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/intro-to-pytorch/Part 5 - Inference and Validation (Solution).ipynb b/intro-to-pytorch/Part 5 - Inference and Validation (Solution).ipynb index 117bb5e3c9..8822969466 100644 --- a/intro-to-pytorch/Part 5 - Inference and Validation (Solution).ipynb +++ b/intro-to-pytorch/Part 5 - Inference and Validation (Solution).ipynb @@ -426,8 +426,8 @@ " test_losses.append(test_loss/len(testloader))\n", "\n", " print(\"Epoch: {}/{}.. \".format(e+1, epochs),\n", - " \"Training Loss: {:.3f}.. \".format(running_loss/len(trainloader)),\n", - " \"Test Loss: {:.3f}.. \".format(test_loss/len(testloader)),\n", + " \"Training Loss: {:.3f}.. \".format(train_losses[-1]),\n", + " \"Test Loss: {:.3f}.. \".format(test_losses[-1]),\n", " \"Test Accuracy: {:.3f}\".format(accuracy/len(testloader)))" ] },