Skip to content

Commit 40fb603

Browse files
authored
Replace model.forward with model
As per pytorch documentation use of model.forward is discouraged. https://discuss.pytorch.org/t/any-different-between-model-input-and-model-forward-input/3690
1 parent 4850dd4 commit 40fb603

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

intro-to-pytorch/Part 3 - Training Neural Networks (Solution).ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@
494494
"optimizer.zero_grad()\n",
495495
"\n",
496496
"# Forward pass, then backward pass, then update weights\n",
497-
"output = model.forward(images)\n",
497+
"output = model(images)\n",
498498
"loss = criterion(output, labels)\n",
499499
"loss.backward()\n",
500500
"print('Gradient -', model[0].weight.grad)"
@@ -581,7 +581,7 @@
581581
" # TODO: Training pass\n",
582582
" optimizer.zero_grad()\n",
583583
" \n",
584-
" output = model.forward(images)\n",
584+
" output = model(images)\n",
585585
" loss = criterion(output, labels)\n",
586586
" loss.backward()\n",
587587
" optimizer.step()\n",
@@ -625,7 +625,7 @@
625625
"img = images[0].view(1, 784)\n",
626626
"# Turn off gradients to speed up this part\n",
627627
"with torch.no_grad():\n",
628-
" logps = model.forward(img)\n",
628+
" logps = model(img)\n",
629629
"\n",
630630
"# Output of the network are logits, need to take softmax for probabilities\n",
631631
"ps = torch.exp(logps)\n",

0 commit comments

Comments
 (0)