Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating fixes and issues of notebook #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions notebooks/pytorch_mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
"outputs": [],
"source": [
"#Import Libraries\n",
"\n",
"\n",
"import argparse\n",
"import torch\n",
"import torch.nn as nn\n",
Expand Down Expand Up @@ -91,7 +89,7 @@
"class Net(nn.Module):\n",
" #This defines the structure of the NN.\n",
" def __init__(self):\n",
" NUM_CLASSES = 0\n",
" NUM_CLASSES = 10\n",
" super(Net, self).__init__()\n",
" self.conv1 = nn.Conv2d(1, 10, kernel_size=5)\n",
" self.conv2 = nn.Conv2d(10, 20, kernel_size=5)\n",
Expand Down Expand Up @@ -149,14 +147,16 @@
" model.eval()\n",
" test_loss = 0\n",
" correct = 0\n",
" for data, target in test_loader:\n",
" if CUDA:\n",
" data, target = data.cuda(), target.cuda()\n",
" data, target = Variable(data, volatile=True), Variable(target)\n",
" output = model(data)\n",
" test_loss += F.nll_loss(output, target, size_average=False).data # sum up batch loss\n",
" pred = output.data.max(1, keepdim=True)[1] # get the index of the max log-probability\n",
" # ToDo: correct = ???\n",
" with torch.no_grad():\n",
" for data, target in test_loader:\n",
" if CUDA:\n",
" data, target = data.cuda(), target.cuda()\n",
" data, target = Variable(data), Variable(target)\n",
" output = model(data)\n",
" test_loss += F.nll_loss(output, target, reduction='sum').item() # sum up batch loss\n",
" pred = output.data.max(1, keepdim=True)[1] # get the index of the max log-probability\n",
" # ToDo: correct = ???\n",
" correct += pred.eq(target.view_as(pred)).sum().item()\n",
"\n",
" test_loss /= len(test_loader.dataset)\n",
" print('\\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\\n'.format(\n",
Expand Down Expand Up @@ -216,7 +216,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.7"
"version": "3.11.0rc1"
}
},
"nbformat": 4,
Expand Down