Skip to content

Commit 317203c

Browse files
authored
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.
1 parent 0acb97a commit 317203c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

intro-to-pytorch/Part 5 - Inference and Validation (Solution).ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@
426426
" test_losses.append(test_loss/len(testloader))\n",
427427
"\n",
428428
" print(\"Epoch: {}/{}.. \".format(e+1, epochs),\n",
429-
" \"Training Loss: {:.3f}.. \".format(running_loss/len(trainloader)),\n",
430-
" \"Test Loss: {:.3f}.. \".format(test_loss/len(testloader)),\n",
429+
" \"Training Loss: {:.3f}.. \".format(train_losses[-1]),\n",
430+
" \"Test Loss: {:.3f}.. \".format(test_losses[-1]),\n",
431431
" \"Test Accuracy: {:.3f}\".format(accuracy/len(testloader)))"
432432
]
433433
},

0 commit comments

Comments
 (0)