From 497356143d8e187c0a3b1a6e2149c57dadc0ec40 Mon Sep 17 00:00:00 2001 From: Nigar Hajiyeva <98217625+1Nigar357@users.noreply.github.com> Date: Sat, 26 Jul 2025 11:41:07 +0400 Subject: [PATCH 1/3] Update PT_Part1_MNIST_Solution.ipynb Correction: Make use of input parameters instead of hardcoding --- lab2/solutions/PT_Part1_MNIST_Solution.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lab2/solutions/PT_Part1_MNIST_Solution.ipynb b/lab2/solutions/PT_Part1_MNIST_Solution.ipynb index 01dc5bfa..fa3f0b7b 100644 --- a/lab2/solutions/PT_Part1_MNIST_Solution.ipynb +++ b/lab2/solutions/PT_Part1_MNIST_Solution.ipynb @@ -417,15 +417,15 @@ " correct_pred = 0\n", " total_pred = 0\n", "\n", - " for images, labels in trainset_loader:\n", + " for images, labels in dataloader:\n", " # Move tensors to GPU so compatible with model\n", " images, labels = images.to(device), labels.to(device)\n", " # Clear gradients before performing backward pass\n", " optimizer.zero_grad()\n", " # Forward pass\n", - " outputs = fc_model(images)\n", + " outputs = model(images)\n", " # Calculate loss based on model predictions\n", - " loss = loss_function(outputs, labels)\n", + " loss = criterion(outputs, labels)\n", " # Backpropagate and update model parameters\n", " loss.backward()\n", " optimizer.step()\n", @@ -500,7 +500,7 @@ " total_pred = 0\n", " # Disable gradient calculations when in inference mode\n", " with torch.no_grad():\n", - " for images, labels in testset_loader:\n", + " for images, labels in dataloader:\n", " # TODO: ensure evalaution happens on the GPU\n", " images, labels = images.to(device), labels.to(device)\n", " # images, labels = # TODO\n", @@ -1026,4 +1026,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} From 622cacab9311c64a3f6cd8a63e37e105efcfc325 Mon Sep 17 00:00:00 2001 From: Nigar Hajiyeva <98217625+1Nigar357@users.noreply.github.com> Date: Sat, 26 Jul 2025 11:46:11 +0400 Subject: [PATCH 2/3] Update PT_Part1_MNIST.ipynb Correction: Manipulate the input parameters to the functions instead of hardcoding --- lab2/PT_Part1_MNIST.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lab2/PT_Part1_MNIST.ipynb b/lab2/PT_Part1_MNIST.ipynb index bcfae490..9f48fb51 100644 --- a/lab2/PT_Part1_MNIST.ipynb +++ b/lab2/PT_Part1_MNIST.ipynb @@ -413,17 +413,17 @@ " correct_pred = 0\n", " total_pred = 0\n", "\n", - " for images, labels in trainset_loader:\n", + " for images, labels in dataloader:\n", " # Move tensors to GPU so compatible with model\n", " images, labels = images.to(device), labels.to(device)\n", "\n", " # Forward pass\n", - " outputs = fc_model(images)\n", + " outputs = model(images)\n", "\n", " # Clear gradients before performing backward pass\n", " optimizer.zero_grad()\n", " # Calculate loss based on model predictions\n", - " loss = loss_function(outputs, labels)\n", + " loss = criterion(outputs, labels)\n", " # Backpropagate and update model parameters\n", " loss.backward()\n", " optimizer.step()\n", @@ -498,7 +498,7 @@ " total_pred = 0\n", " # Disable gradient calculations when in inference mode\n", " with torch.no_grad():\n", - " for images, labels in testset_loader:\n", + " for images, labels in dataloader:\n", " # TODO: ensure evalaution happens on the GPU\n", " images, labels = # TODO\n", "\n", From 2b1f75c2984257dc9e65c1468d27bfc880bee782 Mon Sep 17 00:00:00 2001 From: Nigar Hajiyeva <98217625+1Nigar357@users.noreply.github.com> Date: Sat, 26 Jul 2025 11:55:42 +0400 Subject: [PATCH 3/3] Update PT_Part1_MNIST_Solution.ipynb Change the input parameter of the evaluate function from trainset_loader to testset_loader --- lab2/solutions/PT_Part1_MNIST_Solution.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab2/solutions/PT_Part1_MNIST_Solution.ipynb b/lab2/solutions/PT_Part1_MNIST_Solution.ipynb index fa3f0b7b..5ab77df6 100644 --- a/lab2/solutions/PT_Part1_MNIST_Solution.ipynb +++ b/lab2/solutions/PT_Part1_MNIST_Solution.ipynb @@ -533,7 +533,7 @@ " return test_loss, test_acc\n", "\n", "# TODO: call the evaluate function to evaluate the trained model!!\n", - "test_loss, test_acc = evaluate(fc_model, trainset_loader, loss_function)\n", + "test_loss, test_acc = evaluate(fc_model, testset_loader, loss_function)\n", "# test_loss, test_acc = # TODO\n", "\n", "print('Test accuracy:', test_acc)"