mirror of
https://github.com/mrdbourke/pytorch-deep-learning.git
synced 2026-11-27 06:07:09 +00:00
update computer vision notebook
This commit is contained in:
1 parent
8256947ba7
commit
04b8f3f844
1 file changed
+668
-106
+668
-106
@@ -222,8 +222,8 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(<torch.utils.data.dataloader.DataLoader at 0x7ff77378c3a0>,\n",
|
||||
" <torch.utils.data.dataloader.DataLoader at 0x7ff773792250>,\n",
|
||||
"(<torch.utils.data.dataloader.DataLoader at 0x7fbf725f4e20>,\n",
|
||||
" <torch.utils.data.dataloader.DataLoader at 0x7fbf725f44f0>,\n",
|
||||
" 1875,\n",
|
||||
" 313)"
|
||||
]
|
||||
@@ -443,85 +443,85 @@
|
||||
"\n",
|
||||
"Epoch 1\n",
|
||||
"----------\n",
|
||||
"Loss: 2.29050 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.54511 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.35242 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.56000 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.45745 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.38494 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.37864 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.50732 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 2.34053 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.63385 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.49907 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.26303 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.53534 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.36563 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.68232 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.18253 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 0\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.49405 | Test accuracy: 82.79%\n",
|
||||
"Test loss: 0.50175 | Test accuracy: 82.47%\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Epoch 2\n",
|
||||
"----------\n",
|
||||
"Loss: 0.46565 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.35532 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.51560 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.39630 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.46742 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.65435 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.43886 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.54917 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.57853 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.36582 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.36852 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.35338 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.36890 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.34529 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.33107 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.46185 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 1\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.47412 | Test accuracy: 83.47%\n",
|
||||
"Test loss: 0.52408 | Test accuracy: 81.76%\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Epoch 3\n",
|
||||
"----------\n",
|
||||
"Loss: 0.43452 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.28021 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.38773 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.58577 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.42423 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.49480 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.37182 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.57941 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.38698 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.34827 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.42298 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.53404 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.48242 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.22668 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.45466 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.41813 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 2\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.49569 | Test accuracy: 81.96%\n",
|
||||
"Test loss: 0.51340 | Test accuracy: 82.92%\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Epoch 4\n",
|
||||
"----------\n",
|
||||
"Loss: 0.45295 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.42439 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.21994 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.62966 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.56810 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.50444 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.31636 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.42834 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.37360 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.33119 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.20297 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.39649 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.51343 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.50143 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.36421 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.51659 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 3\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.46010 | Test accuracy: 83.86%\n",
|
||||
"Test loss: 0.47379 | Test accuracy: 83.18%\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Epoch 5\n",
|
||||
"----------\n",
|
||||
"Loss: 0.34907 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.16921 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.47753 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.22700 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.29167 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.17559 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.47119 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.40790 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.26910 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.16825 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.23860 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.24782 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.36713 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.31626 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.24531 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.52060 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 4\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.48020 | Test accuracy: 82.81%\n",
|
||||
"Test loss: 0.46712 | Test accuracy: 83.57%\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Train time on cpu: 26.796 seconds\n"
|
||||
"Train time on cpu: 26.651 seconds\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -601,8 +601,8 @@
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'model_name': 'FashionMNISTModelV0',\n",
|
||||
" 'model_loss': 0.47988951206207275,\n",
|
||||
" 'model_acc': 82.80750798722045}"
|
||||
" 'model_loss': 0.46738308668136597,\n",
|
||||
" 'model_acc': 83.55630990415335}"
|
||||
]
|
||||
},
|
||||
"execution_count": 17,
|
||||
@@ -840,81 +840,81 @@
|
||||
"text": [
|
||||
"Epoch: 0\n",
|
||||
"---------\n",
|
||||
"Loss: 2.28875 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.73451 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.41080 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.49171 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.44563 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.60425 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.52514 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.24773 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 2.31576 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.84441 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.72745 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.48854 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.48070 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.34006 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.60718 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.17817 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 0\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.46868 | Test accuracy: 83.77%\n",
|
||||
"Test loss: 0.46140 | Test accuracy: 83.58%\n",
|
||||
"\n",
|
||||
"Epoch: 1\n",
|
||||
"---------\n",
|
||||
"Loss: 0.73131 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.43385 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.49286 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.53182 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.41964 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.30735 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.38858 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.57935 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.56453 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.34874 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.34462 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.28178 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.34664 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.35043 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.28332 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.34145 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 1\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.41356 | Test accuracy: 85.20%\n",
|
||||
"Test loss: 0.44406 | Test accuracy: 84.48%\n",
|
||||
"\n",
|
||||
"Epoch: 2\n",
|
||||
"---------\n",
|
||||
"Loss: 0.29244 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.27456 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.49385 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.27834 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.53015 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.60976 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.33836 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.39315 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.28065 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.27538 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.32969 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.50899 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.35316 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.20153 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.30891 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.33071 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 2\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.42642 | Test accuracy: 83.88%\n",
|
||||
"Test loss: 0.40107 | Test accuracy: 85.62%\n",
|
||||
"\n",
|
||||
"Epoch: 3\n",
|
||||
"---------\n",
|
||||
"Loss: 0.34869 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.24878 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.48041 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.27290 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.34400 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.24063 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.56060 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.31512 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.26100 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.28107 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.06934 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.32541 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.33877 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.24971 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.25175 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.32383 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 3\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.38704 | Test accuracy: 86.24%\n",
|
||||
"Test loss: 0.38116 | Test accuracy: 86.37%\n",
|
||||
"\n",
|
||||
"Epoch: 4\n",
|
||||
"---------\n",
|
||||
"Loss: 0.25267 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.16645 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.27790 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.25012 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.17404 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.43705 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.28275 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.46345 | Looked at 56000/60000 samples\n",
|
||||
"Loss: 0.20655 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.18057 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.14731 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.17487 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.35683 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.25929 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.19088 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.46857 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 4\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.39585 | Test accuracy: 85.99%\n",
|
||||
"Test loss: 0.37307 | Test accuracy: 86.46%\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Train time on cuda: 27.786 seconds\n"
|
||||
"Train time on cuda: 28.382 seconds\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -956,10 +956,10 @@
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m/tmp/ipykernel_114809/3491452440.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmanual_seed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m42\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m model_1_results = eval_model(model=model_1, \n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mdata_loader\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtest_dataloader\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mloss_fn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mloss_fn\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/tmp/ipykernel_114809/915416713.py\u001b[0m in \u001b[0;36meval_model\u001b[0;34m(model, data_loader, loss_fn, accuracy_fn)\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minference_mode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdata_loader\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0my_pred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mloss_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_pred\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0macc\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0maccuracy_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_true\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_pred\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0my_pred\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/tmp/ipykernel_474092/2379562874.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m#UPTOHERE\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# Make sure model eval code can run on CPU...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m model_1_results = eval_model(model=model_1, \n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mdata_loader\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtest_dataloader\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mloss_fn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mloss_fn\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/tmp/ipykernel_474092/1274930794.py\u001b[0m in \u001b[0;36meval_model\u001b[0;34m(model, data_loader, loss_fn, accuracy_fn)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minference_mode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdata_loader\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0my_pred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mloss_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_pred\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0macc\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0maccuracy_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_true\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_pred\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0my_pred\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1049\u001b[0m if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001b[1;32m 1050\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1051\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1052\u001b[0m \u001b[0;31m# Do not call functions when jit is used\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[0mfull_backward_hooks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnon_full_backward_hooks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/tmp/ipykernel_114809/2755272479.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, x)\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlayer_stack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||
"\u001b[0;32m/tmp/ipykernel_474092/2755272479.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, x)\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlayer_stack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1049\u001b[0m if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001b[1;32m 1050\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1051\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1052\u001b[0m \u001b[0;31m# Do not call functions when jit is used\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[0mfull_backward_hooks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnon_full_backward_hooks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/container.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, input)\u001b[0m\n\u001b[1;32m 137\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 138\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mmodule\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 139\u001b[0;31m \u001b[0minput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodule\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 140\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1049\u001b[0m if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001b[1;32m 1050\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1051\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1052\u001b[0m \u001b[0;31m# Do not call functions when jit is used\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[0mfull_backward_hooks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnon_full_backward_hooks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
@@ -977,7 +977,51 @@
|
||||
"model_1_results = eval_model(model=model_1, \n",
|
||||
" data_loader=test_dataloader,\n",
|
||||
" loss_fn=loss_fn, \n",
|
||||
" accuracy_fn=accuracy_fn)\n",
|
||||
" accuracy_fn=accuracy_fn) # will error due to `eval_model()` not using device agnostic code \n",
|
||||
"model_1_results "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'model_name': 'FashionMNISTModelV1',\n",
|
||||
" 'model_loss': 0.37321436405181885,\n",
|
||||
" 'model_acc': 86.46166134185303}"
|
||||
]
|
||||
},
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Move values to device\n",
|
||||
"torch.manual_seed(42)\n",
|
||||
"def eval_model(model, data_loader, loss_fn, accuracy_fn):\n",
|
||||
" loss, acc = 0, 0\n",
|
||||
" model.eval()\n",
|
||||
" with torch.inference_mode():\n",
|
||||
" for X, y in data_loader:\n",
|
||||
" X, y = X.to(device, non_blocking=True), y.to(device, non_blocking=True)\n",
|
||||
" y_pred = model(X)\n",
|
||||
" loss += loss_fn(y_pred, y)\n",
|
||||
" acc += accuracy_fn(y_true=y, y_pred=y_pred.argmax(dim=1))\n",
|
||||
" \n",
|
||||
" # Scale loss and acc\n",
|
||||
" loss /= len(data_loader)\n",
|
||||
" acc /= len(data_loader)\n",
|
||||
" return {\"model_name\": model.__class__.__name__, # only works when model was created with a class\n",
|
||||
" \"model_loss\": loss.item(),\n",
|
||||
" \"model_acc\": acc}\n",
|
||||
"\n",
|
||||
"model_1_results = eval_model(model=model_1, data_loader=test_dataloader,\n",
|
||||
" loss_fn=loss_fn, accuracy_fn=accuracy_fn\n",
|
||||
")\n",
|
||||
"model_1_results"
|
||||
]
|
||||
},
|
||||
@@ -990,7 +1034,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -999,6 +1043,522 @@
|
||||
"# Use same functions to train and eval"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 138,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"FashionMNISTModelV2(\n",
|
||||
" (block_1): Sequential(\n",
|
||||
" (0): Conv2d(1, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
||||
" (1): ReLU()\n",
|
||||
" (2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
||||
" (3): ReLU()\n",
|
||||
" (4): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n",
|
||||
" )\n",
|
||||
" (block_2): Sequential(\n",
|
||||
" (0): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
||||
" (1): ReLU()\n",
|
||||
" (2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
||||
" (3): ReLU()\n",
|
||||
" (4): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n",
|
||||
" )\n",
|
||||
" (classifier): Sequential(\n",
|
||||
" (0): Flatten(start_dim=1, end_dim=-1)\n",
|
||||
" (1): Linear(in_features=6272, out_features=10, bias=True)\n",
|
||||
" )\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
"execution_count": 138,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# class FashionMNISTModelV2(nn.Module):\n",
|
||||
"# \"\"\"\n",
|
||||
"# Model architecture copying TinyVGG from: \n",
|
||||
"# https://poloclub.github.io/cnn-explainer/\n",
|
||||
"# \"\"\"\n",
|
||||
"# def __init__(self, input_shape, hidden_units, output_shape):\n",
|
||||
"# super().__init__()\n",
|
||||
"# self.layer_stack = nn.Sequential(\n",
|
||||
"# # nn.Flatten(), # flatten inputs into single vector\n",
|
||||
"# nn.Conv2d(in_channels=1, \n",
|
||||
"# out_channels=hidden_units, \n",
|
||||
"# kernel_size=3),\n",
|
||||
"# nn.ReLU(),\n",
|
||||
"# nn.Conv2d(hidden_units, \n",
|
||||
"# hidden_units,\n",
|
||||
"# 3),\n",
|
||||
"# nn.ReLU(),\n",
|
||||
"# nn.MaxPool2d(2),\n",
|
||||
"# nn.Conv2d(hidden_units, hidden_units, 3),\n",
|
||||
"# nn.ReLU(),\n",
|
||||
"# nn.MaxPool2d(2),\n",
|
||||
"# nn.Linear(in_features=hidden_units, out_features=output_shape)\n",
|
||||
"# )\n",
|
||||
" \n",
|
||||
"# def forward(self, x):\n",
|
||||
"# return self.layer_stack(x)\n",
|
||||
"\n",
|
||||
"# model_2 = FashionMNISTModelV2(input_shape=784, \n",
|
||||
"# hidden_units=128, \n",
|
||||
"# output_shape=len(class_names)).to(device)\n",
|
||||
"# model_2\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Model 2 line by line\n",
|
||||
"class FashionMNISTModelV2(nn.Module):\n",
|
||||
" \"\"\"\n",
|
||||
" Model architecture copying TinyVGG from: \n",
|
||||
" https://poloclub.github.io/cnn-explainer/\n",
|
||||
" \"\"\"\n",
|
||||
" def __init__(self, input_shape, hidden_units, output_shape):\n",
|
||||
" super().__init__()\n",
|
||||
" self.block_1 = nn.Sequential(\n",
|
||||
" nn.Conv2d(in_channels=1, \n",
|
||||
" out_channels=hidden_units, \n",
|
||||
" kernel_size=3,\n",
|
||||
" padding=1),\n",
|
||||
" nn.ReLU(),\n",
|
||||
" nn.Conv2d(hidden_units, \n",
|
||||
" hidden_units,\n",
|
||||
" 3,\n",
|
||||
" padding=1),\n",
|
||||
" nn.ReLU(),\n",
|
||||
" nn.MaxPool2d(2)\n",
|
||||
" )\n",
|
||||
" self.block_2 = nn.Sequential(\n",
|
||||
" nn.Conv2d(hidden_units, hidden_units, 3, padding=1),\n",
|
||||
" nn.ReLU(),\n",
|
||||
" nn.Conv2d(hidden_units, hidden_units, 3, padding=1),\n",
|
||||
" nn.ReLU(),\n",
|
||||
" nn.MaxPool2d(2)\n",
|
||||
" )\n",
|
||||
" self.classifier = nn.Sequential(\n",
|
||||
" nn.Flatten(),\n",
|
||||
" nn.Linear(in_features=hidden_units*7*7, out_features=10)\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" def forward(self, x):\n",
|
||||
" x = self.block_1(x)\n",
|
||||
" # print(x.shape)\n",
|
||||
" x = self.block_2(x)\n",
|
||||
" # print(x.shape)\n",
|
||||
" x = self.classifier(x)\n",
|
||||
" # print(x.shape)\n",
|
||||
" return x\n",
|
||||
"\n",
|
||||
"model_2 = FashionMNISTModelV2(input_shape=784, \n",
|
||||
" hidden_units=128, \n",
|
||||
" output_shape=len(class_names)).to(device)\n",
|
||||
"model_2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 139,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"torch.Size([32, 1, 28, 28])"
|
||||
]
|
||||
},
|
||||
"execution_count": 139,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"input, label = next(iter(train_dataloader))\n",
|
||||
"input.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 140,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"torch.Size([32, 128, 4, 4])"
|
||||
]
|
||||
},
|
||||
"execution_count": 140,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"torch.Size([32, 128, 4, 4])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 131,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"16384"
|
||||
]
|
||||
},
|
||||
"execution_count": 131,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"32*128*4"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 141,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Setup loss and optimizer\n",
|
||||
"loss_fn = nn.CrossEntropyLoss()\n",
|
||||
"optimizer = torch.optim.Adam(model_2.parameters(), lr=0.001)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 142,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Epoch: 0\n",
|
||||
"---------\n",
|
||||
"Loss: 2.30738 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.43484 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.31472 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.19138 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.33043 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.30320 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.40622 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.09584 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 0\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.28750 | Test accuracy: 89.62%\n",
|
||||
"\n",
|
||||
"Epoch: 1\n",
|
||||
"---------\n",
|
||||
"Loss: 0.17540 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.23340 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.12453 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.21017 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.24231 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.18512 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.15422 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.07558 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 1\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.25693 | Test accuracy: 90.46%\n",
|
||||
"\n",
|
||||
"Epoch: 2\n",
|
||||
"---------\n",
|
||||
"Loss: 0.22539 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.23084 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.20147 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.48792 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.12466 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.05566 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.19315 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.20613 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 2\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.23476 | Test accuracy: 91.76%\n",
|
||||
"\n",
|
||||
"Epoch: 3\n",
|
||||
"---------\n",
|
||||
"Loss: 0.10456 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.10810 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.09960 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.37311 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.21742 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.11252 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.08921 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.06983 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 3\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.23468 | Test accuracy: 91.86%\n",
|
||||
"\n",
|
||||
"Epoch: 4\n",
|
||||
"---------\n",
|
||||
"Loss: 0.04223 | Looked at 0/60000 samples\n",
|
||||
"Loss: 0.10640 | Looked at 8000/60000 samples\n",
|
||||
"Loss: 0.11237 | Looked at 16000/60000 samples\n",
|
||||
"Loss: 0.09687 | Looked at 24000/60000 samples\n",
|
||||
"Loss: 0.24647 | Looked at 32000/60000 samples\n",
|
||||
"Loss: 0.20868 | Looked at 40000/60000 samples\n",
|
||||
"Loss: 0.16323 | Looked at 48000/60000 samples\n",
|
||||
"Loss: 0.41087 | Looked at 56000/60000 samples\n",
|
||||
"\n",
|
||||
"Testing for Epoch: 4\n",
|
||||
"----------\n",
|
||||
"Test loss: 0.22767 | Test accuracy: 92.21%\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Train time on cuda: 39.690 seconds\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Train and test model\n",
|
||||
"torch.manual_seed(42)\n",
|
||||
"\n",
|
||||
"# Measure time\n",
|
||||
"from timeit import default_timer as timer\n",
|
||||
"train_time_start_model_2 = timer()\n",
|
||||
"\n",
|
||||
"epochs=5\n",
|
||||
"for epoch in range(epochs):\n",
|
||||
" print(f\"Epoch: {epoch}\\n---------\")\n",
|
||||
" train(data_loader=train_dataloader, \n",
|
||||
" model=model_2, \n",
|
||||
" loss_fn=loss_fn,\n",
|
||||
" optimizer=optimizer\n",
|
||||
" )\n",
|
||||
" test(data_loader=test_dataloader,\n",
|
||||
" model=model_2,\n",
|
||||
" loss_fn=loss_fn\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"train_time_end_model_2 = timer()\n",
|
||||
"total_train_time_model_2 = print_train_time(start=train_time_start_model_2,\n",
|
||||
" end=train_time_end_model_2,\n",
|
||||
" device=device)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 143,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'model_name': 'FashionMNISTModelV2',\n",
|
||||
" 'model_loss': 0.22770197689533234,\n",
|
||||
" 'model_acc': 92.20247603833866}"
|
||||
]
|
||||
},
|
||||
"execution_count": 143,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"model_2_results = eval_model(\n",
|
||||
" model=model_2,\n",
|
||||
" data_loader=test_dataloader,\n",
|
||||
" loss_fn=loss_fn,\n",
|
||||
" accuracy_fn=accuracy_fn\n",
|
||||
")\n",
|
||||
"model_2_results"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 144,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"({'model_name': 'FashionMNISTModelV0',\n",
|
||||
" 'model_loss': 0.46738308668136597,\n",
|
||||
" 'model_acc': 83.55630990415335},\n",
|
||||
" {'model_name': 'FashionMNISTModelV1',\n",
|
||||
" 'model_loss': 0.37321436405181885,\n",
|
||||
" 'model_acc': 86.46166134185303},\n",
|
||||
" {'model_name': 'FashionMNISTModelV2',\n",
|
||||
" 'model_loss': 0.22770197689533234,\n",
|
||||
" 'model_acc': 92.20247603833866})"
|
||||
]
|
||||
},
|
||||
"execution_count": 144,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"model_0_results, model_1_results, model_2_results"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 145,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>model_name</th>\n",
|
||||
" <th>model_loss</th>\n",
|
||||
" <th>model_acc</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>FashionMNISTModelV0</td>\n",
|
||||
" <td>0.467383</td>\n",
|
||||
" <td>83.556310</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>FashionMNISTModelV1</td>\n",
|
||||
" <td>0.373214</td>\n",
|
||||
" <td>86.461661</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>FashionMNISTModelV2</td>\n",
|
||||
" <td>0.227702</td>\n",
|
||||
" <td>92.202476</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" model_name model_loss model_acc\n",
|
||||
"0 FashionMNISTModelV0 0.467383 83.556310\n",
|
||||
"1 FashionMNISTModelV1 0.373214 86.461661\n",
|
||||
"2 FashionMNISTModelV2 0.227702 92.202476"
|
||||
]
|
||||
},
|
||||
"execution_count": 145,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"compare_results = pd.DataFrame([model_0_results, model_1_results, model_2_results])\n",
|
||||
"compare_results"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 149,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<AxesSubplot:>"
|
||||
]
|
||||
},
|
||||
"execution_count": 149,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"image/png": "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",
|
||||
"text/plain": [
|
||||
"<Figure size 432x288 with 1 Axes>"
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"needs_background": "light"
|
||||
},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"compare_results[\"model_acc\"].plot(kind=\"bar\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Make predictions with best model"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 151,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def make_predictions(model, data):\n",
|
||||
" model.eval()\n",
|
||||
" with torch.inference_mode():\n",
|
||||
" # 1. Forward pass\n",
|
||||
" preds = model(data)\n",
|
||||
" return preds"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 157,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "TypeError",
|
||||
"evalue": "conv2d() received an invalid combination of arguments - got (list, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:\n * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)\n didn't match because some of the arguments have invalid types: (!list!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)\n * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)\n didn't match because some of the arguments have invalid types: (!list!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)\n",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m/tmp/ipykernel_474092/1246729839.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpreds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmake_predictions\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmodel_2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdata\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtest_data\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mpreds\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/tmp/ipykernel_474092/127388332.py\u001b[0m in \u001b[0;36mmake_predictions\u001b[0;34m(model, data)\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minference_mode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# 1. Forward pass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mpreds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mpreds\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1049\u001b[0m if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001b[1;32m 1050\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1051\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1052\u001b[0m \u001b[0;31m# Do not call functions when jit is used\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[0mfull_backward_hooks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnon_full_backward_hooks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/tmp/ipykernel_474092/927672735.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, x)\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 68\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mblock_1\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 69\u001b[0m \u001b[0;31m# print(x.shape)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 70\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mblock_2\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1049\u001b[0m if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001b[1;32m 1050\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1051\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1052\u001b[0m \u001b[0;31m# Do not call functions when jit is used\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[0mfull_backward_hooks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnon_full_backward_hooks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/container.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, input)\u001b[0m\n\u001b[1;32m 137\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 138\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mmodule\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 139\u001b[0;31m \u001b[0minput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodule\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 140\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1049\u001b[0m if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001b[1;32m 1050\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1051\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1052\u001b[0m \u001b[0;31m# Do not call functions when jit is used\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[0mfull_backward_hooks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnon_full_backward_hooks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/conv.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, input)\u001b[0m\n\u001b[1;32m 441\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 442\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mTensor\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mTensor\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 443\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_conv_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mweight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbias\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 444\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 445\u001b[0m \u001b[0;32mclass\u001b[0m \u001b[0mConv3d\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_ConvNd\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m~/code/pytorch/env/lib/python3.9/site-packages/torch/nn/modules/conv.py\u001b[0m in \u001b[0;36m_conv_forward\u001b[0;34m(self, input, weight, bias)\u001b[0m\n\u001b[1;32m 437\u001b[0m \u001b[0mweight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbias\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstride\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 438\u001b[0m _pair(0), self.dilation, self.groups)\n\u001b[0;32m--> 439\u001b[0;31m return F.conv2d(input, weight, bias, self.stride,\n\u001b[0m\u001b[1;32m 440\u001b[0m self.padding, self.dilation, self.groups)\n\u001b[1;32m 441\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;31mTypeError\u001b[0m: conv2d() received an invalid combination of arguments - got (list, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:\n * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)\n didn't match because some of the arguments have invalid types: (!list!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)\n * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)\n didn't match because some of the arguments have invalid types: (!list!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"preds = make_predictions(model=model_2, data=[data for data, label in test_data][0])\n",
|
||||
"preds"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -1009,11 +1569,13 @@
|
||||
"* ~~upload accuracy function to helper_functions.py~~\n",
|
||||
"* ~~\"We're writing a lot of boiler plate code... but that's to practice\"~~\n",
|
||||
"* ~~bring in non-linearity for model 1 (it works on FashionMNIST)~~\n",
|
||||
"* Create Conv model to really step things up - https://poloclub.github.io/cnn-explainer/ \n",
|
||||
"* Calculate all different model results (on same data)\n",
|
||||
" * Eval model 1\n",
|
||||
" * Eval model 2\n",
|
||||
"* Compare model results\n",
|
||||
"* ~Create Conv model to really step things up - https://poloclub.github.io/cnn-explainer/ \n",
|
||||
"* ~Calculate all different model results (on same data)~\n",
|
||||
" * ~Eval model 1~\n",
|
||||
" * ~Eval model 2~\n",
|
||||
"* ~Compare model results~\n",
|
||||
"* Make predictions with best model\n",
|
||||
"* Save and load best model\n",
|
||||
"\n",
|
||||
"# Next notebook... (keep them short and sweet)\n",
|
||||
"* then bring in another dataset (custom dataset)\n",
|
||||
|
||||
Reference in new issue
Block a user