Skip to content

Commit 1be1333

Browse files
authored
Merge pull request #53 from jaintj95/master
Replace model.forward() with model()
2 parents 0aa064a + 40fb603 commit 1be1333

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
"optimizer.zero_grad()\n",
381381
"\n",
382382
"# Forward pass, then backward pass, then update weights\n",
383-
"output = model.forward(images)\n",
383+
"output = model(images)\n",
384384
"loss = criterion(output, labels)\n",
385385
"loss.backward()\n",
386386
"print('Gradient -', model[0].weight.grad)"
@@ -463,7 +463,7 @@
463463
"img = images[0].view(1, 784)\n",
464464
"# Turn off gradients to speed up this part\n",
465465
"with torch.no_grad():\n",
466-
" logits = model.forward(img)\n",
466+
" logits = model(img)\n",
467467
"\n",
468468
"# Output of the network are logits, need to take softmax for probabilities\n",
469469
"ps = F.softmax(logits, dim=1)\n",

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)