From 4850dd4697e58a8ee76320e4ad7a8fff0b3f9cc9 Mon Sep 17 00:00:00 2001 From: Tejas Jain <36858630+jaintj95@users.noreply.github.com> Date: Tue, 20 Nov 2018 01:26:47 +0530 Subject: [PATCH 1/2] 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 --- .../Part 3 - Training Neural Networks (Exercises).ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/intro-to-pytorch/Part 3 - Training Neural Networks (Exercises).ipynb b/intro-to-pytorch/Part 3 - Training Neural Networks (Exercises).ipynb index c62185150e..14b0e99882 100644 --- a/intro-to-pytorch/Part 3 - Training Neural Networks (Exercises).ipynb +++ b/intro-to-pytorch/Part 3 - Training Neural Networks (Exercises).ipynb @@ -380,7 +380,7 @@ "optimizer.zero_grad()\n", "\n", "# Forward pass, then backward pass, then update weights\n", - "output = model.forward(images)\n", + "output = model(images)\n", "loss = criterion(output, labels)\n", "loss.backward()\n", "print('Gradient -', model[0].weight.grad)" @@ -463,7 +463,7 @@ "img = images[0].view(1, 784)\n", "# Turn off gradients to speed up this part\n", "with torch.no_grad():\n", - " logits = model.forward(img)\n", + " logits = model(img)\n", "\n", "# Output of the network are logits, need to take softmax for probabilities\n", "ps = F.softmax(logits, dim=1)\n", From 40fb603687cda5cd4ac83d7ebdecea39ab00ae9d Mon Sep 17 00:00:00 2001 From: Tejas Jain <36858630+jaintj95@users.noreply.github.com> Date: Tue, 20 Nov 2018 01:30:03 +0530 Subject: [PATCH 2/2] 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 --- .../Part 3 - Training Neural Networks (Solution).ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/intro-to-pytorch/Part 3 - Training Neural Networks (Solution).ipynb b/intro-to-pytorch/Part 3 - Training Neural Networks (Solution).ipynb index 9e6410af78..fed41b4acc 100644 --- a/intro-to-pytorch/Part 3 - Training Neural Networks (Solution).ipynb +++ b/intro-to-pytorch/Part 3 - Training Neural Networks (Solution).ipynb @@ -494,7 +494,7 @@ "optimizer.zero_grad()\n", "\n", "# Forward pass, then backward pass, then update weights\n", - "output = model.forward(images)\n", + "output = model(images)\n", "loss = criterion(output, labels)\n", "loss.backward()\n", "print('Gradient -', model[0].weight.grad)" @@ -581,7 +581,7 @@ " # TODO: Training pass\n", " optimizer.zero_grad()\n", " \n", - " output = model.forward(images)\n", + " output = model(images)\n", " loss = criterion(output, labels)\n", " loss.backward()\n", " optimizer.step()\n", @@ -625,7 +625,7 @@ "img = images[0].view(1, 784)\n", "# Turn off gradients to speed up this part\n", "with torch.no_grad():\n", - " logps = model.forward(img)\n", + " logps = model(img)\n", "\n", "# Output of the network are logits, need to take softmax for probabilities\n", "ps = torch.exp(logps)\n",