grant commited on
Commit Β·
f2ca6a2
1
Parent(s): 71832f4
Added stuff
Browse filesFiles changed (5)
- .gitignoreAdded+2
- .ipynb_checkpoints/relu_test-checkpoint.ipynbAdded+377
- .ipynb_checkpoints/relu_test-improve-checkpoint.ipynbAdded+376
- relu_test-improve.ipynbAdded+376
- relu_test.ipynb+94-79
12.venvdata123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377{ "cells": [ { "cell_type": "code", "execution_count": 11, "id": "b174f7b9-e276-4abe-80eb-3d8a54d4f74e", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import torch\n", "import torch.nn as nn\n", "import torch.optim as optim\n", "from torch.utils.data import DataLoader, TensorDataset \n", "import matplotlib.pyplot as plt\n", "\n", "from torchvision import datasets\n", "from torchvision.transforms import v2\n", "# Transforms transform and augemtn data" ] }, { "cell_type": "code", "execution_count": 12, "id": "0cf2dd6f-993a-4842-b8b4-51e8d10e27c6", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 26.4M/26.4M [00:01<00:00, 14.0MB/s]\n", "100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 29.5k/29.5k [00:00<00:00, 244kB/s]\n", "100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 4.42M/4.42M [00:01<00:00, 4.40MB/s]\n", "100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5.15k/5.15k [00:00<00:00, 13.7MB/s]\n" ] } ], "source": [ "transform = v2.Compose([\n", " v2.ToImage(), \n", " v2.ToDtype(torch.float32, scale=True)\n", " ])\n", " # Gets converted to image, then to float32, likely cause this is inout to model\n", " # This is simply the transform function which the data gets passed through\n", "\n", "training_data = datasets.FashionMNIST(\n", " root=\"data\",\n", " train=True,\n", " download=True,\n", " transform=transform,\n", ")\n", "\n", "testing_data = datasets.FashionMNIST(\n", " root=\"data\",\n", " train=False,\n", " download=True,\n", " transform=transform,\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "795434de-b097-4ed1-8fc6-c299cea3112c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([3, 224, 224])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "H, W = 32, 32\n", "img = torch.randint(0, 256, size=(3, H, W), dtype=torch.uint8)\n", "# Series of things which it gets pushed through\n", "trans = v2.Compose([\n", " v2.RandomResizedCrop(size=(224, 224), antialias=True),\n", "])\n", "img = trans(img)\n", "img.shape" ] }, { "cell_type": "code", "execution_count": 14, "id": "59d4072f-396f-4c44-8bdb-cb882b4f390f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'cpu'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Hypers\n", "batch_size=64\n", "device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n", "lr=1e-3\n", "epochs=5\n", "device" ] }, { "cell_type": "code", "execution_count": 15, "id": "4720f599-5268-4f4a-8023-398018f997ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "torch.Size([64, 1, 28, 28])\n", "torch.Size([64, 784])\n" ] } ], "source": [ "train_dl = DataLoader(training_data, batch_size=batch_size)\n", "test_dl = DataLoader(testing_data, batch_size=batch_size)\n", "\n", "flatten = nn.Flatten()\n", "\n", "for x,y in test_dl:\n", " print(x.shape)\n", " print(flatten(x).shape)\n", " break" ] }, { "cell_type": "code", "execution_count": 16, "id": "4fed909d-6b9e-4564-9230-caadfbaadf84", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NN(\n", " (flatten): Flatten(start_dim=1, end_dim=-1)\n", " (lin_relu_stack): Sequential(\n", " (0): Linear(in_features=784, out_features=512, bias=True)\n", " (1): ReLU()\n", " (2): Linear(in_features=512, out_features=512, bias=True)\n", " (3): ReLU()\n", " (4): Linear(in_features=512, out_features=10, bias=True)\n", " )\n", ")\n" ] } ], "source": [ "class NN(nn.Module):\n", " def __init__(self):\n", " super().__init__()\n", " self.flatten = nn.Flatten()\n", " # Fire one after another\n", " self.lin_relu_stack = nn.Sequential(\n", " nn.Linear(28*28, 512),\n", " nn.ReLU(),\n", " nn.Linear(512, 512),\n", " nn.ReLU(),\n", " nn.Linear(512, 10)\n", " )\n", " def forward(self, x):\n", " x = self.flatten(x)\n", " logits = self.lin_relu_stack(x)\n", " return logits\n", "\n", "model = NN().to(device)\n", "print(model)" ] }, { "cell_type": "code", "execution_count": 17, "id": "6e42fdbc-c949-47c9-9b91-06f8769bdbc0", "metadata": {}, "outputs": [], "source": [ "loss_fn = nn.CrossEntropyLoss()\n", "optim = torch.optim.SGD(model.parameters(), lr=lr)" ] }, { "cell_type": "code", "execution_count": 18, "id": "d8786c61-42c5-4263-be52-75e22b017f80", "metadata": {}, "outputs": [], "source": [ "def train(dl, model, loss_fn, optim):\n", " size = len(dl.dataset)\n", " model.train()\n", " # This likely ensures the model has a gradient as well\n", " # Set in train mode, allows for less deterministic results, more exploration?\n", " for batch, (q, a) in enumerate(dl):\n", " q, a = q.to(device), a.to(device)\n", "\n", " pred = model(q)\n", " loss = loss_fn(pred, a)\n", "\n", " loss.backward() # Computes the gradient associated with tensor\n", " optim.step() # Optimize\n", " optim.zero_grad() # Resets the gradients of all associated tensors (likely params)\n", "\n", " if batch % 100 == 0:\n", " loss, current = loss.item(), (batch + 1) * len(q)\n", " # Pads the values to the right, >\n", " # Sets the max size, 7\n", " # Sets as float\n", " print(f\"loss: {loss:>7f} [{current:>5d}/{size:>5d}]\")\n", "\n", "# Notice how we are batching. So we compute the entire batch, then find the loss, then optimize\n", "# There is also mini batching. So you can see that if we had a batch size of one, small variences...\n", "# in data could allow for noisy optimization" ] }, { "cell_type": "code", "execution_count": 19, "id": "b7146832-4333-4ca8-9633-30e0e39d466c", "metadata": {}, "outputs": [], "source": [ "def test(dl, model, loss_fn):\n", " size = len(dl.dataset)\n", " n_batches = len(dl)\n", " model.eval()\n", " test_loss, correct = 0, 0\n", " with torch.no_grad():\n", " # Doesnt build graph for decent used by .backward() etc. Just not needed\n", " for q, a in dl:\n", " q, a = q.to(device), a.to(device)\n", " pred = model(q)\n", " test_loss += loss_fn(pred, a).item()\n", " # .item gets the raw value of the tensor\n", " correct += (pred.argmax(1) == a).type(torch.float).sum().item()\n", " test_loss /= n_batches\n", " correct /= size\n", " print(f\"Test Err: \\n Acc: {(100*correct):>0.1f}%, Avg Loss: {test_loss:>8f} \\n\")\n" ] }, { "cell_type": "code", "execution_count": 20, "id": "54558a8f-1d7f-430d-a802-e46c73596307", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Epoch 1\n", "-----------------------\n", "loss: 2.302843 [ 64/60000]\n", "loss: 2.293552 [ 6464/60000]\n", "loss: 2.271770 [12864/60000]\n", "loss: 2.268235 [19264/60000]\n", "loss: 2.259464 [25664/60000]\n", "loss: 2.233306 [32064/60000]\n", "loss: 2.242224 [38464/60000]\n", "loss: 2.209635 [44864/60000]\n", "loss: 2.204026 [51264/60000]\n", "loss: 2.189499 [57664/60000]\n", "Test Err: \n", " Acc: 45.2%, Avg Loss: 2.176645 \n", "\n", "Epoch 2\n", "-----------------------\n", "loss: 2.180576 [ 64/60000]\n", "loss: 2.177760 [ 6464/60000]\n", "loss: 2.122090 [12864/60000]\n", "loss: 2.143509 [19264/60000]\n", "loss: 2.106071 [25664/60000]\n", "loss: 2.046749 [32064/60000]\n", "loss: 2.081548 [38464/60000]\n", "loss: 2.002130 [44864/60000]\n", "loss: 2.000836 [51264/60000]\n", "loss: 1.960623 [57664/60000]\n", "Test Err: \n", " Acc: 58.5%, Avg Loss: 1.944671 \n", "\n", "Epoch 3\n", "-----------------------\n", "loss: 1.963853 [ 64/60000]\n", "loss: 1.953807 [ 6464/60000]\n", "loss: 1.830755 [12864/60000]\n", "loss: 1.877165 [19264/60000]\n", "loss: 1.792784 [25664/60000]\n", "loss: 1.723131 [32064/60000]\n", "loss: 1.755769 [38464/60000]\n", "loss: 1.642658 [44864/60000]\n", "loss: 1.660763 [51264/60000]\n", "loss: 1.578437 [57664/60000]\n", "Test Err: \n", " Acc: 61.6%, Avg Loss: 1.582071 \n", "\n", "Epoch 4\n", "-----------------------\n", "loss: 1.633815 [ 64/60000]\n", "loss: 1.617035 [ 6464/60000]\n", "loss: 1.448106 [12864/60000]\n", "loss: 1.527922 [19264/60000]\n", "loss: 1.420378 [25664/60000]\n", "loss: 1.390574 [32064/60000]\n", "loss: 1.414548 [38464/60000]\n", "loss: 1.322819 [44864/60000]\n", "loss: 1.363828 [51264/60000]\n", "loss: 1.268618 [57664/60000]\n", "Test Err: \n", " Acc: 63.0%, Avg Loss: 1.293045 \n", "\n", "Epoch 5\n", "-----------------------\n", "loss: 1.362215 [ 64/60000]\n", "loss: 1.356474 [ 6464/60000]\n", "loss: 1.176312 [12864/60000]\n", "loss: 1.284292 [19264/60000]\n", "loss: 1.168589 [25664/60000]\n", "loss: 1.177593 [32064/60000]\n", "loss: 1.202365 [38464/60000]\n", "loss: 1.128387 [44864/60000]\n", "loss: 1.177669 [51264/60000]\n", "loss: 1.092795 [57664/60000]\n", "Test Err: \n", " Acc: 64.5%, Avg Loss: 1.115378 \n", "\n", "Done\n" ] } ], "source": [ "for t in range(epochs):\n", " print(f\"Epoch {t+1}\\n-----------------------\")\n", " train(train_dl, model, loss_fn, optim)\n", " test(test_dl, model, loss_fn)\n", "print(\"Done\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.2" } }, "nbformat": 4, "nbformat_minor": 5}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b174f7b9-e276-4abe-80eb-3d8a54d4f74e", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import torch\n", "import torch.nn as nn\n", "import torch.optim as optim\n", "from torch.utils.data import DataLoader, TensorDataset \n", "import matplotlib.pyplot as plt\n", "\n", "from torchvision import datasets\n", "from torchvision.transforms import v2\n", "# Transforms transform and augemtn data" ] }, { "cell_type": "code", "execution_count": 2, "id": "0cf2dd6f-993a-4842-b8b4-51e8d10e27c6", "metadata": {}, "outputs": [], "source": [ "transform = v2.Compose([\n", " v2.ToImage(), \n", " v2.ToDtype(torch.float32, scale=True)\n", " ])\n", " # Gets converted to image, then to float32, likely cause this is inout to model\n", " # This is simply the transform function which the data gets passed through\n", "\n", "training_data = datasets.FashionMNIST(\n", " root=\"data\",\n", " train=True,\n", " download=True,\n", " transform=transform,\n", ")\n", "\n", "testing_data = datasets.FashionMNIST(\n", " root=\"data\",\n", " train=False,\n", " download=True,\n", " transform=transform,\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "id": "795434de-b097-4ed1-8fc6-c299cea3112c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([3, 224, 224])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "H, W = 32, 32\n", "img = torch.randint(0, 256, size=(3, H, W), dtype=torch.uint8)\n", "# Series of things which it gets pushed through\n", "trans = v2.Compose([\n", " v2.RandomResizedCrop(size=(224, 224), antialias=True),\n", "])\n", "img = trans(img)\n", "img.shape" ] }, { "cell_type": "code", "execution_count": 4, "id": "59d4072f-396f-4c44-8bdb-cb882b4f390f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'cpu'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Hypers\n", "batch_size=64\n", "device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n", "lr=1e-3\n", "epochs=5\n", "device" ] }, { "cell_type": "code", "execution_count": 5, "id": "4720f599-5268-4f4a-8023-398018f997ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "torch.Size([64, 1, 28, 28])\n", "torch.Size([64, 784])\n" ] } ], "source": [ "train_dl = DataLoader(training_data, batch_size=batch_size)\n", "test_dl = DataLoader(testing_data, batch_size=batch_size)\n", "\n", "flatten = nn.Flatten()\n", "\n", "for x,y in test_dl:\n", " print(x.shape)\n", " print(flatten(x).shape)\n", " break" ] }, { "cell_type": "code", "execution_count": 6, "id": "4fed909d-6b9e-4564-9230-caadfbaadf84", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NN(\n", " (flatten): Flatten(start_dim=1, end_dim=-1)\n", " (lin_relu_stack): Sequential(\n", " (0): Linear(in_features=784, out_features=512, bias=True)\n", " (1): ReLU()\n", " (2): Linear(in_features=512, out_features=10, bias=True)\n", " )\n", ")\n" ] } ], "source": [ "class NN(nn.Module):\n", " def __init__(self):\n", " super().__init__()\n", " self.flatten = nn.Flatten()\n", " # Fire one after another\n", " self.lin_relu_stack = nn.Sequential(\n", " nn.Linear(28*28, 512),\n", " nn.ReLU(),\n", " # nn.GELU(),\n", " # nn.Linear(512, 512),\n", " # nn.GELU(),\n", " nn.Linear(512, 10)\n", " )\n", " def forward(self, x):\n", " x = self.flatten(x)\n", " logits = self.lin_relu_stack(x)\n", " return logits\n", "\n", "model = NN().to(device)\n", "print(model)\n", "\n", "# We build the network as if we are going to pass in one item at a time\n", "# So, 28 x 28" ] }, { "cell_type": "code", "execution_count": 7, "id": "6e42fdbc-c949-47c9-9b91-06f8769bdbc0", "metadata": {}, "outputs": [], "source": [ "loss_fn = nn.CrossEntropyLoss()\n", "optim = torch.optim.SGD(model.parameters(), lr=lr)" ] }, { "cell_type": "code", "execution_count": 8, "id": "d8786c61-42c5-4263-be52-75e22b017f80", "metadata": {}, "outputs": [], "source": [ "def train(dl, model, loss_fn, optim):\n", " size = len(dl.dataset)\n", " model.train()\n", " # This likely ensures the model has a gradient as well\n", " # Set in train mode, allows for less deterministic results, more exploration?\n", " for batch, (q, a) in enumerate(dl):\n", " q, a = q.to(device), a.to(device)\n", "\n", " pred = model(q)\n", " loss = loss_fn(pred, a)\n", "\n", " loss.backward() # Computes the gradient associated with tensor\n", " optim.step() # Optimize\n", " optim.zero_grad() # Resets the gradients of all associated tensors (likely params)\n", "\n", " if batch % 100 == 0:\n", " loss, current = loss.item(), (batch + 1) * len(q)\n", " # Pads the values to the right, >\n", " # Sets the max size, 7\n", " # Sets as float\n", " print(f\"loss: {loss:>7f} [{current:>5d}/{size:>5d}]\")\n", "\n", "# Notice how we are batching. So we compute the entire batch, then find the loss, then optimize\n", "# There is also mini batching. So you can see that if we had a batch size of one, small variences...\n", "# in data could allow for noisy optimization" ] }, { "cell_type": "code", "execution_count": 9, "id": "b7146832-4333-4ca8-9633-30e0e39d466c", "metadata": {}, "outputs": [], "source": [ "def test(dl, model, loss_fn):\n", " size = len(dl.dataset)\n", " n_batches = len(dl)\n", " model.eval()\n", " test_loss, correct = 0, 0\n", " with torch.no_grad():\n", " # Doesnt build graph for decent used by .backward() etc. Just not needed\n", " for q, a in dl:\n", " q, a = q.to(device), a.to(device)\n", " pred = model(q)\n", " test_loss += loss_fn(pred, a).item()\n", " # .item gets the raw value of the tensor\n", " correct += (pred.argmax(1) == a).type(torch.float).sum().item()\n", " test_loss /= n_batches\n", " correct /= size\n", " print(f\"Test Err: \\n Acc: {(100*correct):>0.1f}%, Avg Loss: {test_loss:>8f} \\n\")\n" ] }, { "cell_type": "code", "execution_count": 10, "id": "54558a8f-1d7f-430d-a802-e46c73596307", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Epoch 1\n", "-----------------------\n", "loss: 2.337799 [ 64/60000]\n", "loss: 2.269365 [ 6464/60000]\n", "loss: 2.200223 [12864/60000]\n", "loss: 2.173634 [19264/60000]\n", "loss: 2.098508 [25664/60000]\n", "loss: 2.021035 [32064/60000]\n", "loss: 2.012522 [38464/60000]\n", "loss: 1.926182 [44864/60000]\n", "loss: 1.933493 [51264/60000]\n", "loss: 1.804537 [57664/60000]\n", "Test Err: \n", " Acc: 59.3%, Avg Loss: 1.815768 \n", "\n", "Epoch 2\n", "-----------------------\n", "loss: 1.862893 [ 64/60000]\n", "loss: 1.820787 [ 6464/60000]\n", "loss: 1.676155 [12864/60000]\n", "loss: 1.721919 [19264/60000]\n", "loss: 1.576428 [25664/60000]\n", "loss: 1.537179 [32064/60000]\n", "loss: 1.535113 [38464/60000]\n", "loss: 1.448765 [44864/60000]\n", "loss: 1.490439 [51264/60000]\n", "loss: 1.347647 [57664/60000]\n", "Test Err: \n", " Acc: 65.0%, Avg Loss: 1.385211 \n", "\n", "Epoch 3\n", "-----------------------\n", "loss: 1.454105 [ 64/60000]\n", "loss: 1.431710 [ 6464/60000]\n", "loss: 1.260652 [12864/60000]\n", "loss: 1.366012 [19264/60000]\n", "loss: 1.215632 [25664/60000]\n", "loss: 1.223819 [32064/60000]\n", "loss: 1.232290 [38464/60000]\n", "loss: 1.170137 [44864/60000]\n", "loss: 1.224482 [51264/60000]\n", "loss: 1.102639 [57664/60000]\n", "Test Err: \n", " Acc: 66.1%, Avg Loss: 1.140274 \n", "\n", "Epoch 4\n", "-----------------------\n", "loss: 1.204628 [ 64/60000]\n", "loss: 1.210266 [ 6464/60000]\n", "loss: 1.019733 [12864/60000]\n", "loss: 1.169079 [19264/60000]\n", "loss: 1.022622 [25664/60000]\n", "loss: 1.047017 [32064/60000]\n", "loss: 1.073016 [38464/60000]\n", "loss: 1.020203 [44864/60000]\n", "loss: 1.076051 [51264/60000]\n", "loss: 0.975902 [57664/60000]\n", "Test Err: \n", " Acc: 67.3%, Avg Loss: 1.003286 \n", "\n", "Epoch 5\n", "-----------------------\n", "loss: 1.054180 [ 64/60000]\n", "loss: 1.083647 [ 6464/60000]\n", "loss: 0.875336 [12864/60000]\n", "loss: 1.053822 [19264/60000]\n", "loss: 0.913836 [25664/60000]\n", "loss: 0.938795 [32064/60000]\n", "loss: 0.979879 [38464/60000]\n", "loss: 0.932063 [44864/60000]\n", "loss: 0.985123 [51264/60000]\n", "loss: 0.900464 [57664/60000]\n", "Test Err: \n", " Acc: 68.7%, Avg Loss: 0.918494 \n", "\n", "Done\n" ] } ], "source": [ "for t in range(epochs):\n", " print(f\"Epoch {t+1}\\n-----------------------\")\n", " train(train_dl, model, loss_fn, optim)\n", " test(test_dl, model, loss_fn)\n", "print(\"Done\")" ] }, { "cell_type": "code", "execution_count": null, "id": "4a0a345c-b497-4583-92df-d4190f28525c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.2" } }, "nbformat": 4, "nbformat_minor": 5}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b174f7b9-e276-4abe-80eb-3d8a54d4f74e", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import torch\n", "import torch.nn as nn\n", "import torch.optim as optim\n", "from torch.utils.data import DataLoader, TensorDataset \n", "import matplotlib.pyplot as plt\n", "\n", "from torchvision import datasets\n", "from torchvision.transforms import v2\n", "# Transforms transform and augemtn data" ] }, { "cell_type": "code", "execution_count": 2, "id": "0cf2dd6f-993a-4842-b8b4-51e8d10e27c6", "metadata": {}, "outputs": [], "source": [ "transform = v2.Compose([\n", " v2.ToImage(), \n", " v2.ToDtype(torch.float32, scale=True)\n", " ])\n", " # Gets converted to image, then to float32, likely cause this is inout to model\n", " # This is simply the transform function which the data gets passed through\n", "\n", "training_data = datasets.FashionMNIST(\n", " root=\"data\",\n", " train=True,\n", " download=True,\n", " transform=transform,\n", ")\n", "\n", "testing_data = datasets.FashionMNIST(\n", " root=\"data\",\n", " train=False,\n", " download=True,\n", " transform=transform,\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "id": "795434de-b097-4ed1-8fc6-c299cea3112c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([3, 224, 224])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "H, W = 32, 32\n", "img = torch.randint(0, 256, size=(3, H, W), dtype=torch.uint8)\n", "# Series of things which it gets pushed through\n", "trans = v2.Compose([\n", " v2.RandomResizedCrop(size=(224, 224), antialias=True),\n", "])\n", "img = trans(img)\n", "img.shape" ] }, { "cell_type": "code", "execution_count": 4, "id": "59d4072f-396f-4c44-8bdb-cb882b4f390f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'cpu'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Hypers\n", "batch_size=64\n", "device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n", "lr=1e-3\n", "epochs=5\n", "device" ] }, { "cell_type": "code", "execution_count": 5, "id": "4720f599-5268-4f4a-8023-398018f997ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "torch.Size([64, 1, 28, 28])\n", "torch.Size([64, 784])\n" ] } ], "source": [ "train_dl = DataLoader(training_data, batch_size=batch_size)\n", "test_dl = DataLoader(testing_data, batch_size=batch_size)\n", "\n", "flatten = nn.Flatten()\n", "\n", "for x,y in test_dl:\n", " print(x.shape)\n", " print(flatten(x).shape)\n", " break" ] }, { "cell_type": "code", "execution_count": 6, "id": "4fed909d-6b9e-4564-9230-caadfbaadf84", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NN(\n", " (flatten): Flatten(start_dim=1, end_dim=-1)\n", " (lin_relu_stack): Sequential(\n", " (0): Linear(in_features=784, out_features=512, bias=True)\n", " (1): ReLU()\n", " (2): Linear(in_features=512, out_features=10, bias=True)\n", " )\n", ")\n" ] } ], "source": [ "class NN(nn.Module):\n", " def __init__(self):\n", " super().__init__()\n", " self.flatten = nn.Flatten()\n", " # Fire one after another\n", " self.lin_relu_stack = nn.Sequential(\n", " nn.Linear(28*28, 512),\n", " nn.ReLU(),\n", " # nn.GELU(),\n", " # nn.Linear(512, 512),\n", " # nn.GELU(),\n", " nn.Linear(512, 10)\n", " )\n", " def forward(self, x):\n", " x = self.flatten(x)\n", " logits = self.lin_relu_stack(x)\n", " return logits\n", "\n", "model = NN().to(device)\n", "print(model)\n", "\n", "# We build the network as if we are going to pass in one item at a time\n", "# So, 28 x 28" ] }, { "cell_type": "code", "execution_count": 7, "id": "6e42fdbc-c949-47c9-9b91-06f8769bdbc0", "metadata": {}, "outputs": [], "source": [ "loss_fn = nn.CrossEntropyLoss()\n", "optim = torch.optim.SGD(model.parameters(), lr=lr)" ] }, { "cell_type": "code", "execution_count": 8, "id": "d8786c61-42c5-4263-be52-75e22b017f80", "metadata": {}, "outputs": [], "source": [ "def train(dl, model, loss_fn, optim):\n", " size = len(dl.dataset)\n", " model.train()\n", " # This likely ensures the model has a gradient as well\n", " # Set in train mode, allows for less deterministic results, more exploration?\n", " for batch, (q, a) in enumerate(dl):\n", " q, a = q.to(device), a.to(device)\n", "\n", " pred = model(q)\n", " loss = loss_fn(pred, a)\n", "\n", " loss.backward() # Computes the gradient associated with tensor\n", " optim.step() # Optimize\n", " optim.zero_grad() # Resets the gradients of all associated tensors (likely params)\n", "\n", " if batch % 100 == 0:\n", " loss, current = loss.item(), (batch + 1) * len(q)\n", " # Pads the values to the right, >\n", " # Sets the max size, 7\n", " # Sets as float\n", " print(f\"loss: {loss:>7f} [{current:>5d}/{size:>5d}]\")\n", "\n", "# Notice how we are batching. So we compute the entire batch, then find the loss, then optimize\n", "# There is also mini batching. So you can see that if we had a batch size of one, small variences...\n", "# in data could allow for noisy optimization" ] }, { "cell_type": "code", "execution_count": 9, "id": "b7146832-4333-4ca8-9633-30e0e39d466c", "metadata": {}, "outputs": [], "source": [ "def test(dl, model, loss_fn):\n", " size = len(dl.dataset)\n", " n_batches = len(dl)\n", " model.eval()\n", " test_loss, correct = 0, 0\n", " with torch.no_grad():\n", " # Doesnt build graph for decent used by .backward() etc. Just not needed\n", " for q, a in dl:\n", " q, a = q.to(device), a.to(device)\n", " pred = model(q)\n", " test_loss += loss_fn(pred, a).item()\n", " # .item gets the raw value of the tensor\n", " correct += (pred.argmax(1) == a).type(torch.float).sum().item()\n", " test_loss /= n_batches\n", " correct /= size\n", " print(f\"Test Err: \\n Acc: {(100*correct):>0.1f}%, Avg Loss: {test_loss:>8f} \\n\")\n" ] }, { "cell_type": "code", "execution_count": 10, "id": "54558a8f-1d7f-430d-a802-e46c73596307", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Epoch 1\n", "-----------------------\n", "loss: 2.337799 [ 64/60000]\n", "loss: 2.269365 [ 6464/60000]\n", "loss: 2.200223 [12864/60000]\n", "loss: 2.173634 [19264/60000]\n", "loss: 2.098508 [25664/60000]\n", "loss: 2.021035 [32064/60000]\n", "loss: 2.012522 [38464/60000]\n", "loss: 1.926182 [44864/60000]\n", "loss: 1.933493 [51264/60000]\n", "loss: 1.804537 [57664/60000]\n", "Test Err: \n", " Acc: 59.3%, Avg Loss: 1.815768 \n", "\n", "Epoch 2\n", "-----------------------\n", "loss: 1.862893 [ 64/60000]\n", "loss: 1.820787 [ 6464/60000]\n", "loss: 1.676155 [12864/60000]\n", "loss: 1.721919 [19264/60000]\n", "loss: 1.576428 [25664/60000]\n", "loss: 1.537179 [32064/60000]\n", "loss: 1.535113 [38464/60000]\n", "loss: 1.448765 [44864/60000]\n", "loss: 1.490439 [51264/60000]\n", "loss: 1.347647 [57664/60000]\n", "Test Err: \n", " Acc: 65.0%, Avg Loss: 1.385211 \n", "\n", "Epoch 3\n", "-----------------------\n", "loss: 1.454105 [ 64/60000]\n", "loss: 1.431710 [ 6464/60000]\n", "loss: 1.260652 [12864/60000]\n", "loss: 1.366012 [19264/60000]\n", "loss: 1.215632 [25664/60000]\n", "loss: 1.223819 [32064/60000]\n", "loss: 1.232290 [38464/60000]\n", "loss: 1.170137 [44864/60000]\n", "loss: 1.224482 [51264/60000]\n", "loss: 1.102639 [57664/60000]\n", "Test Err: \n", " Acc: 66.1%, Avg Loss: 1.140274 \n", "\n", "Epoch 4\n", "-----------------------\n", "loss: 1.204628 [ 64/60000]\n", "loss: 1.210266 [ 6464/60000]\n", "loss: 1.019733 [12864/60000]\n", "loss: 1.169079 [19264/60000]\n", "loss: 1.022622 [25664/60000]\n", "loss: 1.047017 [32064/60000]\n", "loss: 1.073016 [38464/60000]\n", "loss: 1.020203 [44864/60000]\n", "loss: 1.076051 [51264/60000]\n", "loss: 0.975902 [57664/60000]\n", "Test Err: \n", " Acc: 67.3%, Avg Loss: 1.003286 \n", "\n", "Epoch 5\n", "-----------------------\n", "loss: 1.054180 [ 64/60000]\n", "loss: 1.083647 [ 6464/60000]\n", "loss: 0.875336 [12864/60000]\n", "loss: 1.053822 [19264/60000]\n", "loss: 0.913836 [25664/60000]\n", "loss: 0.938795 [32064/60000]\n", "loss: 0.979879 [38464/60000]\n", "loss: 0.932063 [44864/60000]\n", "loss: 0.985123 [51264/60000]\n", "loss: 0.900464 [57664/60000]\n", "Test Err: \n", " Acc: 68.7%, Avg Loss: 0.918494 \n", "\n", "Done\n" ] } ], "source": [ "for t in range(epochs):\n", " print(f\"Epoch {t+1}\\n-----------------------\")\n", " train(train_dl, model, loss_fn, optim)\n", " test(test_dl, model, loss_fn)\n", "print(\"Done\")" ] }, { "cell_type": "code", "execution_count": null, "id": "4a0a345c-b497-4583-92df-d4190f28525c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.2" } }, "nbformat": 4, "nbformat_minor": 5}1 unmodified line234567812 unmodified lines2122232425262728293019 unmodified lines505152535455563 unmodified lines6061626364656611 unmodified lines78798081828384858687888990919293949596979820 unmodified lines11912012112212312412538 unmodified lines1641651661671681691704 unmodified lines17517617717817918018127 unmodified lines20921021121221321421518 unmodified lines2342352362372382392403 unmodified lines2442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203216 unmodified lines32832933033133233333433533633733833934034112 unmodified lines3543553563573583593601 unmodified line"cells": [{"cell_type": "code","execution_count": 3,"id": "b174f7b9-e276-4abe-80eb-3d8a54d4f74e","metadata": {},"outputs": [],12 unmodified lines},{"cell_type": "code","execution_count": 27,"id": "0cf2dd6f-993a-4842-b8b4-51e8d10e27c6","metadata": {},"outputs": [],"source": ["transform = v2.Compose([\n"," v2.ToImage(), \n",19 unmodified lines},{"cell_type": "code","execution_count": 14,"id": "795434de-b097-4ed1-8fc6-c299cea3112c","metadata": {},"outputs": [3 unmodified lines"torch.Size([3, 224, 224])"]},"execution_count": 14,"metadata": {},"output_type": "execute_result"}11 unmodified lines},{"cell_type": "code","execution_count": 51,"id": "59d4072f-396f-4c44-8bdb-cb882b4f390f","metadata": {},"outputs": [],"source": ["# Hypers\n","batch_size=64\n","device=\"cpu\"\n","lr=1e-3\n","epochs=5"]},{"cell_type": "code","execution_count": 47,"id": "4720f599-5268-4f4a-8023-398018f997ba","metadata": {},"outputs": [20 unmodified lines},{"cell_type": "code","execution_count": 48,"id": "4fed909d-6b9e-4564-9230-caadfbaadf84","metadata": {},"outputs": [38 unmodified lines},{"cell_type": "code","execution_count": 49,"id": "6e42fdbc-c949-47c9-9b91-06f8769bdbc0","metadata": {},"outputs": [],4 unmodified lines},{"cell_type": "code","execution_count": 53,"id": "d8786c61-42c5-4263-be52-75e22b017f80","metadata": {},"outputs": [],27 unmodified lines},{"cell_type": "code","execution_count": 73,"id": "b7146832-4333-4ca8-9633-30e0e39d466c","metadata": {},"outputs": [],18 unmodified lines},{"cell_type": "code","execution_count": 74,"id": "54558a8f-1d7f-430d-a802-e46c73596307","metadata": {},"outputs": [3 unmodified lines"text": ["Epoch 1\n","-----------------------\n","loss: 0.953114 [ 64/60000]\n","loss: 0.987902 [ 6464/60000]\n","loss: 0.792046 [12864/60000]\n","loss: 0.965094 [19264/60000]\n","loss: 0.840583 [25664/60000]\n","loss: 0.862857 [32064/60000]\n","loss: 0.915543 [38464/60000]\n","loss: 0.878772 [44864/60000]\n","loss: 0.924747 [51264/60000]\n","loss: 0.854615 [57664/60000]\n","Test Err: \n"," Acc: 68.5%, Avg Loss: 0.856918 \n","\n","Epoch 2\n","-----------------------\n","loss: 0.885750 [ 64/60000]\n","loss: 0.937377 [ 6464/60000]\n","loss: 0.730796 [12864/60000]\n","loss: 0.916519 [19264/60000]\n","loss: 0.798170 [25664/60000]\n","loss: 0.810955 [32064/60000]\n","loss: 0.873083 [38464/60000]\n","loss: 0.843384 [44864/60000]\n","loss: 0.882100 [51264/60000]\n","loss: 0.817359 [57664/60000]\n","Test Err: \n"," Acc: 69.8%, Avg Loss: 0.817336 \n","\n","Epoch 3\n","-----------------------\n","loss: 0.831787 [ 64/60000]\n","loss: 0.897163 [ 6464/60000]\n","loss: 0.682640 [12864/60000]\n","loss: 0.879060 [19264/60000]\n","loss: 0.765995 [25664/60000]\n","loss: 0.770658 [32064/60000]\n","loss: 0.838664 [38464/60000]\n","loss: 0.817186 [44864/60000]\n","loss: 0.848692 [51264/60000]\n","loss: 0.787484 [57664/60000]\n","Test Err: \n"," Acc: 71.1%, Avg Loss: 0.785908 \n","\n","Epoch 4\n","-----------------------\n","loss: 0.787119 [ 64/60000]\n","loss: 0.863401 [ 6464/60000]\n","loss: 0.643335 [12864/60000]\n","loss: 0.849343 [19264/60000]\n","loss: 0.740239 [25664/60000]\n","loss: 0.738741 [32064/60000]\n","loss: 0.809381 [38464/60000]\n","loss: 0.796576 [44864/60000]\n","loss: 0.821449 [51264/60000]\n","loss: 0.762421 [57664/60000]\n","Test Err: \n"," Acc: 72.2%, Avg Loss: 0.759883 \n","\n","Epoch 5\n","-----------------------\n","loss: 0.749226 [ 64/60000]\n","loss: 0.833617 [ 6464/60000]\n","loss: 0.610202 [12864/60000]\n","loss: 0.825011 [19264/60000]\n","loss: 0.718757 [25664/60000]\n","loss: 0.712976 [32064/60000]\n","loss: 0.783492 [38464/60000]\n","loss: 0.779352 [44864/60000]\n","loss: 0.798640 [51264/60000]\n","loss: 0.740714 [57664/60000]\n","Test Err: \n"," Acc: 73.3%, Avg Loss: 0.737533 \n","\n","Done\n"]6 unmodified lines" test(test_dl, model, loss_fn)\n","print(\"Done\")"]},{"cell_type": "code","execution_count": null,"id": "4a0a345c-b497-4583-92df-d4190f28525c","metadata": {},"outputs": [],"source": []}],"metadata": {12 unmodified lines"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3","version": "3.9.25"}},"nbformat": 4,1 unmodified line234567812 unmodified lines21222324252627282930313233343536373839404119 unmodified lines616263646566673 unmodified lines7172737475767711 unmodified lines899091929394959697989910010110210310410510610710810911011111211311411511611711811912012120 unmodified lines14214314414514614714838 unmodified lines1871881891901911921934 unmodified lines19819920020120220320427 unmodified lines23223323423523623723818 unmodified lines2572582592602612622633 unmodified lines2672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433446 unmodified lines35135235335435535612 unmodified lines3693703713723733743751 unmodified line"cells": [{"cell_type": "code","execution_count": 11,"id": "b174f7b9-e276-4abe-80eb-3d8a54d4f74e","metadata": {},"outputs": [],12 unmodified lines},{"cell_type": "code","execution_count": 12,"id": "0cf2dd6f-993a-4842-b8b4-51e8d10e27c6","metadata": {},"outputs": [{"name": "stderr","output_type": "stream","text": ["100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 26.4M/26.4M [00:01<00:00, 14.0MB/s]\n","100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 29.5k/29.5k [00:00<00:00, 244kB/s]\n","100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 4.42M/4.42M [00:01<00:00, 4.40MB/s]\n","100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5.15k/5.15k [00:00<00:00, 13.7MB/s]\n"]}],"source": ["transform = v2.Compose([\n"," v2.ToImage(), \n",19 unmodified lines},{"cell_type": "code","execution_count": 13,"id": "795434de-b097-4ed1-8fc6-c299cea3112c","metadata": {},"outputs": [3 unmodified lines"torch.Size([3, 224, 224])"]},"execution_count": 13,"metadata": {},"output_type": "execute_result"}11 unmodified lines},{"cell_type": "code","execution_count": 14,"id": "59d4072f-396f-4c44-8bdb-cb882b4f390f","metadata": {},"outputs": [{"data": {"text/plain": ["'cpu'"]},"execution_count": 14,"metadata": {},"output_type": "execute_result"}],"source": ["# Hypers\n","batch_size=64\n","device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n","lr=1e-3\n","epochs=5\n","device"]},{"cell_type": "code","execution_count": 15,"id": "4720f599-5268-4f4a-8023-398018f997ba","metadata": {},"outputs": [20 unmodified lines},{"cell_type": "code","execution_count": 16,"id": "4fed909d-6b9e-4564-9230-caadfbaadf84","metadata": {},"outputs": [38 unmodified lines},{"cell_type": "code","execution_count": 17,"id": "6e42fdbc-c949-47c9-9b91-06f8769bdbc0","metadata": {},"outputs": [],4 unmodified lines},{"cell_type": "code","execution_count": 18,"id": "d8786c61-42c5-4263-be52-75e22b017f80","metadata": {},"outputs": [],27 unmodified lines},{"cell_type": "code","execution_count": 19,"id": "b7146832-4333-4ca8-9633-30e0e39d466c","metadata": {},"outputs": [],18 unmodified lines},{"cell_type": "code","execution_count": 20,"id": "54558a8f-1d7f-430d-a802-e46c73596307","metadata": {},"outputs": [3 unmodified lines"text": ["Epoch 1\n","-----------------------\n","loss: 2.302843 [ 64/60000]\n","loss: 2.293552 [ 6464/60000]\n","loss: 2.271770 [12864/60000]\n","loss: 2.268235 [19264/60000]\n","loss: 2.259464 [25664/60000]\n","loss: 2.233306 [32064/60000]\n","loss: 2.242224 [38464/60000]\n","loss: 2.209635 [44864/60000]\n","loss: 2.204026 [51264/60000]\n","loss: 2.189499 [57664/60000]\n","Test Err: \n"," Acc: 45.2%, Avg Loss: 2.176645 \n","\n","Epoch 2\n","-----------------------\n","loss: 2.180576 [ 64/60000]\n","loss: 2.177760 [ 6464/60000]\n","loss: 2.122090 [12864/60000]\n","loss: 2.143509 [19264/60000]\n","loss: 2.106071 [25664/60000]\n","loss: 2.046749 [32064/60000]\n","loss: 2.081548 [38464/60000]\n","loss: 2.002130 [44864/60000]\n","loss: 2.000836 [51264/60000]\n","loss: 1.960623 [57664/60000]\n","Test Err: \n"," Acc: 58.5%, Avg Loss: 1.944671 \n","\n","Epoch 3\n","-----------------------\n","loss: 1.963853 [ 64/60000]\n","loss: 1.953807 [ 6464/60000]\n","loss: 1.830755 [12864/60000]\n","loss: 1.877165 [19264/60000]\n","loss: 1.792784 [25664/60000]\n","loss: 1.723131 [32064/60000]\n","loss: 1.755769 [38464/60000]\n","loss: 1.642658 [44864/60000]\n","loss: 1.660763 [51264/60000]\n","loss: 1.578437 [57664/60000]\n","Test Err: \n"," Acc: 61.6%, Avg Loss: 1.582071 \n","\n","Epoch 4\n","-----------------------\n","loss: 1.633815 [ 64/60000]\n","loss: 1.617035 [ 6464/60000]\n","loss: 1.448106 [12864/60000]\n","loss: 1.527922 [19264/60000]\n","loss: 1.420378 [25664/60000]\n","loss: 1.390574 [32064/60000]\n","loss: 1.414548 [38464/60000]\n","loss: 1.322819 [44864/60000]\n","loss: 1.363828 [51264/60000]\n","loss: 1.268618 [57664/60000]\n","Test Err: \n"," Acc: 63.0%, Avg Loss: 1.293045 \n","\n","Epoch 5\n","-----------------------\n","loss: 1.362215 [ 64/60000]\n","loss: 1.356474 [ 6464/60000]\n","loss: 1.176312 [12864/60000]\n","loss: 1.284292 [19264/60000]\n","loss: 1.168589 [25664/60000]\n","loss: 1.177593 [32064/60000]\n","loss: 1.202365 [38464/60000]\n","loss: 1.128387 [44864/60000]\n","loss: 1.177669 [51264/60000]\n","loss: 1.092795 [57664/60000]\n","Test Err: \n"," Acc: 64.5%, Avg Loss: 1.115378 \n","\n","Done\n"]6 unmodified lines" test(test_dl, model, loss_fn)\n","print(\"Done\")"]}],"metadata": {12 unmodified lines"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3","version": "3.11.2"}},"nbformat": 4,
.gitignoreAdded+2
.ipynb_checkpoints/relu_test-checkpoint.ipynbAdded+377
.ipynb_checkpoints/relu_test-improve-checkpoint.ipynbAdded+376
relu_test-improve.ipynbAdded+376
relu_test.ipynb+94-79