diff --git a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb index df40b18..7e2d11a 100644 --- a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb +++ b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb @@ -2,11 +2,11 @@ "cells": [ { "cell_type": "code", - "execution_count": 51, + "execution_count": 1, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:50.830757Z", - "start_time": "2020-10-13T05:12:50.826831Z" + "end_time": "2020-10-13T05:57:00.497080Z", + "start_time": "2020-10-13T05:57:00.151314Z" } }, "outputs": [], @@ -139,11 +139,25 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 2, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:52.376404Z", - "start_time": "2020-10-13T05:12:52.297057Z" + "end_time": "2020-10-13T05:57:00.531948Z", + "start_time": "2020-10-13T05:57:00.498549Z" + } + }, + "outputs": [], + "source": [ + "device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2020-10-13T05:57:00.900212Z", + "start_time": "2020-10-13T05:57:00.533714Z" } }, "outputs": [ @@ -179,11 +193,11 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 4, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:52.455907Z", - "start_time": "2020-10-13T05:12:52.443346Z" + "end_time": "2020-10-13T05:57:00.904680Z", + "start_time": "2020-10-13T05:57:00.901784Z" } }, "outputs": [ @@ -204,11 +218,11 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:52.596824Z", - "start_time": "2020-10-13T05:12:52.587281Z" + "end_time": "2020-10-13T05:57:00.953802Z", + "start_time": "2020-10-13T05:57:00.905936Z" } }, "outputs": [ @@ -218,7 +232,7 @@ "deep_ml_curriculum.data.landmass_f3.LandmassF3Patches" ] }, - "execution_count": 54, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -238,11 +252,11 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 6, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:52.885552Z", - "start_time": "2020-10-13T05:12:52.880373Z" + "end_time": "2020-10-13T05:57:01.067516Z", + "start_time": "2020-10-13T05:57:00.955175Z" } }, "outputs": [ @@ -257,10 +271,10 @@ "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGMAAABjCAAAAACqUOFJAAAfXElEQVR4nC3BWcyl52EQ4Hf73m9fzv6f85/599k9mXFsx+6kTpyQuFnagJpSiYICXIBQQe0NElQIJLhFSFx0AaEWCqWlLW3VJF1om2CnsePYju0Zzz7z79vZz7dv78YNzwP/ZwFFnbdKx2mYESeiyHyJFyTy6mG5XBRaEktucZyCKi30aExis9lGCpvnAa0ND7lsDkvWYBiQdlKqSWUyPhsiISI/FLStxrai5C4CgsNj5bOOf7qSJKDmRZwDHZVXQ1VHdOInkWwiJBoFoUPfMx1XnWdlJIDlYKJmQriKuIYsNQZl3VCKZroOsG/hQY19APsgg1/TIr3hnegoZhj6U2Si8yoKSEMSEyIDIuEU9Tyw2gZMeDEMIM7hUYFDpLsZ1WpcKUtyxq2acKzlxgBRo7bHhtYocCsUelH46Bz+fZUx25vbGGaJu4ibCs+Mpq/ZGgq9nBCtsXC1UelqtPDLmRpk1QKmuo5BAI+kBRFokFNUxqh2Ks9G0BVOVehMM5WgoOKRdBMNEsPemoV1i9omTxlpWxlZhdfj0JUEiUAmsi6MpEjLyvYNuLUb666Ph+XYi2DcVAAJpnHbJVIoaBg6ndbVuEjLzZguMJhb2lE7n6k+WSiNuJrJWDk3E10jzcZgnp5PndzFkwt8oSZ0GUqb+d0Wkm1srDQA7JXHOY3IqlGmsFZyy2pKYXBPZ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p0xw6grVS9cOytzRCDWiNQMExowbRqIUqZPO8jiNBpoUDVB0hDV1C5dkWkBBAkHUOgh1jXqmahU1Cr0zKGiAiZBJuUcVAVVXA+sJEJ0IDRecUn0QuBBFmLGg66uINJPWnptVOjS1M0EMJlet5algc8sMm0CgqQaefUEaa4XazWpxCgHvIIls4oCMAulnJCxhTHWsG3AlbParjxGgJMKTEMflrUXc4QtoQ8PyqI0m3mtmUmC4xYwK7M0bIWw9B2prxRIL1OWkkphrSRWEWIdkbKuIXFh4XsJw1UMoAnqGFXcb4n/B27CcxMNEC4tAAAAAElFTkSuQmCC\n", "text/plain": [ - "" + "" ] }, - "execution_count": 55, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -273,11 +287,11 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 7, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:53.043368Z", - "start_time": "2020-10-13T05:12:53.040218Z" + "end_time": "2020-10-13T05:57:01.137930Z", + "start_time": "2020-10-13T05:57:01.068859Z" } }, "outputs": [ @@ -287,7 +301,7 @@ "['Chaotic Horizon', 'Fault', 'Horizon', 'Salt Dome']" ] }, - "execution_count": 56, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -324,11 +338,11 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 8, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:53.337917Z", - "start_time": "2020-10-13T05:12:53.330377Z" + "end_time": "2020-10-13T05:57:01.188867Z", + "start_time": "2020-10-13T05:57:01.140038Z" } }, "outputs": [ @@ -1029,11 +1043,11 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 9, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:53.507346Z", - "start_time": "2020-10-13T05:12:53.500655Z" + "end_time": "2020-10-13T05:57:01.230427Z", + "start_time": "2020-10-13T05:57:01.190460Z" } }, "outputs": [], @@ -1071,11 +1085,11 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 10, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:53.668748Z", - "start_time": "2020-10-13T05:12:53.657666Z" + "end_time": "2020-10-13T05:57:02.831401Z", + "start_time": "2020-10-13T05:57:01.231676Z" } }, "outputs": [ @@ -1084,38 +1098,28 @@ "output_type": "stream", "text": [ "Net(\n", - " (conv): Sequential(\n", - " (0): Conv2d(1, 6, kernel_size=(3, 3), stride=(1, 1))\n", - " (1): ReLU()\n", - " (2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n", - " (3): Conv2d(6, 16, kernel_size=(3, 3), stride=(1, 1))\n", - " (4): ReLU()\n", - " (5): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n", - " )\n", - " (head): Sequential(\n", - " (0): Linear(in_features=8464, out_features=120, bias=True)\n", - " (1): ReLU()\n", - " (2): Linear(in_features=120, out_features=84, bias=True)\n", - " (3): ReLU()\n", - " (4): Linear(in_features=84, out_features=4, bias=True)\n", - " )\n", + " (conv1): Conv2d(1, 6, kernel_size=(3, 3), stride=(1, 1))\n", + " (conv2): Conv2d(6, 16, kernel_size=(3, 3), stride=(1, 1))\n", + " (fc1): Linear(in_features=8464, out_features=120, bias=True)\n", + " (fc2): Linear(in_features=120, out_features=84, bias=True)\n", + " (fc3): Linear(in_features=84, out_features=4, bias=True)\n", ")\n" ] } ], "source": [ "# Create an instance of your network\n", - "net = Net()\n", + "net = Net().to(device)\n", "print(net)" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 11, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:53.854476Z", - "start_time": "2020-10-13T05:12:53.825261Z" + "end_time": "2020-10-13T05:57:03.149187Z", + "start_time": "2020-10-13T05:57:02.832611Z" } }, "outputs": [ @@ -1123,27 +1127,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "========================================================================\n", - " Kernel Shape Output Shape Params Mult-Adds\n", - "Layer \n", - "0_conv.Conv2d_0 [1, 6, 3, 3] [1, 6, 97, 97] 60.0 508.086k\n", - "1_conv.ReLU_1 - [1, 6, 97, 97] - -\n", - "2_conv.MaxPool2d_2 - [1, 6, 48, 48] - -\n", - "3_conv.Conv2d_3 [6, 16, 3, 3] [1, 16, 46, 46] 880.0 1.828224M\n", - "4_conv.ReLU_4 - [1, 16, 46, 46] - -\n", - "5_conv.MaxPool2d_5 - [1, 16, 23, 23] - -\n", - "6_head.Linear_0 [8464, 120] [1, 120] 1.0158M 1.01568M\n", - "7_head.ReLU_1 - [1, 120] - -\n", - "8_head.Linear_2 [120, 84] [1, 84] 10.164k 10.08k\n", - "9_head.ReLU_3 - [1, 84] - -\n", - "10_head.Linear_4 [84, 4] [1, 4] 340.0 336.0\n", - "------------------------------------------------------------------------\n", - " Totals\n", - "Total params 1.027244M\n", - "Trainable params 1.027244M\n", - "Non-trainable params 0.0\n", - "Mult-Adds 3.362406M\n", - "========================================================================\n" + "===========================================================\n", + " Kernel Shape Output Shape Params Mult-Adds\n", + "Layer \n", + "0_conv1 [1, 6, 3, 3] [1, 6, 97, 97] 60 508086\n", + "1_conv2 [6, 16, 3, 3] [1, 16, 46, 46] 880 1828224\n", + "2_fc1 [8464, 120] [1, 120] 1015800 1015680\n", + "3_fc2 [120, 84] [1, 84] 10164 10080\n", + "4_fc3 [84, 4] [1, 4] 340 336\n", + "-----------------------------------------------------------\n", + " Totals\n", + "Total params 1027244\n", + "Trainable params 1027244\n", + "Non-trainable params 0\n", + "Mult-Adds 3362406\n", + "===========================================================\n" ] }, { @@ -1152,7 +1150,7 @@ "1" ] }, - "execution_count": 60, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -1160,7 +1158,7 @@ "source": [ "from deep_ml_curriculum.torchsummaryX import summary\n", "# We can also summarise the number of parameters in each layer\n", - "summary(net, torch.rand((1, 1, 99, 99)))\n", + "summary(net, torch.rand((1, 1, 99, 99)).to(device))\n", "1" ] }, @@ -1179,11 +1177,11 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 12, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:54.130240Z", - "start_time": "2020-10-13T05:12:54.123436Z" + "end_time": "2020-10-13T05:57:03.157672Z", + "start_time": "2020-10-13T05:57:03.150671Z" } }, "outputs": [ @@ -1191,12 +1189,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[ 0.0494, -0.0630, 0.0044, -0.0264]], grad_fn=)\n" + "tensor([[ 0.0054, 0.0994, -0.0771, -0.0366]], device='cuda:0',\n", + " grad_fn=)\n" ] } ], "source": [ - "input = torch.rand(1, 1, 99, 99)\n", + "input = torch.rand(1, 1, 99, 99).to(device)\n", "out = net(input)\n", "\n", "# An array with 4 output, each one corresponding to\n", @@ -1219,21 +1218,21 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 13, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:54.466722Z", - "start_time": "2020-10-13T05:12:54.460610Z" + "end_time": "2020-10-13T05:57:03.216252Z", + "start_time": "2020-10-13T05:57:03.158919Z" } }, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 62, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -1259,11 +1258,11 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 14, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:12:54.729924Z", - "start_time": "2020-10-13T05:12:54.627334Z" + "end_time": "2020-10-13T05:57:03.422893Z", + "start_time": "2020-10-13T05:57:03.217604Z" } }, "outputs": [], @@ -1286,11 +1285,11 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 15, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:19:34.088055Z", - "start_time": "2020-10-13T05:19:34.082007Z" + "end_time": "2020-10-13T05:57:03.437448Z", + "start_time": "2020-10-13T05:57:03.424363Z" } }, "outputs": [], @@ -1305,8 +1304,8 @@ " # Let's divide the data in batches\n", " start_i = i * bs\n", " end_i = start_i + bs\n", - " inputs = x_train[start_i:end_i].unsqueeze(1).float()\n", - " labels = y_train[start_i:end_i].long()\n", + " inputs = x_train[start_i:end_i].unsqueeze(1).float().to(device)\n", + " labels = y_train[start_i:end_i].long().to(device)\n", " \n", " # zero the parameter gradients\n", " optimizer.zero_grad()\n", @@ -1329,11 +1328,11 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 16, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:19:34.216649Z", - "start_time": "2020-10-13T05:19:34.212423Z" + "end_time": "2020-10-13T05:57:03.511459Z", + "start_time": "2020-10-13T05:57:03.438766Z" } }, "outputs": [], @@ -1345,7 +1344,7 @@ " total = 0\n", "\n", " for idx, image in enumerate(x):\n", - " pred = model(image.unsqueeze(0).unsqueeze(0)).argmax()\n", + " pred = model(image.unsqueeze(0).unsqueeze(0).cuda()).argmax()\n", " if int(pred) == int(y[idx]):\n", " correct += 1\n", " total += 1\n", @@ -1357,18 +1356,19 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 17, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:19:49.206830Z", - "start_time": "2020-10-13T05:19:34.370631Z" - } + "end_time": "2020-10-13T05:57:13.177176Z", + "start_time": "2020-10-13T05:57:03.512890Z" + }, + "scrolled": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "62b9d73c0f7244009130dfa8d6bba245", + "model_id": "570d35ae09d4432b894cb59a847ad2b3", "version_major": 2, "version_minor": 0 }, @@ -1383,26 +1383,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "[1, 10] loss: 0.00598\n", - "[1, 20] loss: 0.00589\n", - "[1, 30] loss: 0.00604\n", - "[1, 40] loss: 0.00592\n", - "[1, 50] loss: 0.00596\n", - "[1, 60] loss: 0.00591\n", - "[1, 70] loss: 0.00569\n", - "[1, 80] loss: 0.00576\n", - "[1, 90] loss: 0.00595\n", - "[1, 100] loss: 0.00584\n", - "[1, 110] loss: 0.00582\n", - "[1, 120] loss: 0.00564\n", - "[1, 130] loss: 0.0058\n", - "[1, 140] loss: 0.00568\n", - "[1, 150] loss: 0.00569\n", - "[1, 160] loss: 0.00567\n", - "[1, 170] loss: 0.00559\n", - "[1, 180] loss: 0.00554\n", - "[1, 190] loss: 0.00555\n", - "[1, 200] loss: 0.00561\n", + "[1, 10] loss: 0.0071\n", + "[1, 20] loss: 0.00706\n", + "[1, 30] loss: 0.00698\n", + "[1, 40] loss: 0.00694\n", + "[1, 50] loss: 0.00688\n", + "[1, 60] loss: 0.00685\n", + "[1, 70] loss: 0.0068\n", + "[1, 80] loss: 0.00674\n", + "[1, 90] loss: 0.00672\n", + "[1, 100] loss: 0.00669\n", + "[1, 110] loss: 0.00663\n", + "[1, 120] loss: 0.00656\n", + "[1, 130] loss: 0.00653\n", + "[1, 140] loss: 0.00645\n", + "[1, 150] loss: 0.00642\n", + "[1, 160] loss: 0.00635\n", + "[1, 170] loss: 0.00627\n", + "[1, 180] loss: 0.00619\n", + "[1, 190] loss: 0.0061\n", + "[1, 200] loss: 0.00606\n", "\n", "Finished Training\n", "2371 4417\n", @@ -1427,11 +1427,11 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 18, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:20:36.368158Z", - "start_time": "2020-10-13T05:19:54.642568Z" + "end_time": "2020-10-13T05:57:46.593680Z", + "start_time": "2020-10-13T05:57:13.178565Z" }, "scrolled": true }, @@ -1439,7 +1439,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "37f859ff1cfb40c7b7f17d5c085f81dd", + "model_id": "18161e9d03da4bc198a9bd90c9407a5b", "version_major": 2, "version_minor": 0 }, @@ -1454,106 +1454,106 @@ "name": "stdout", "output_type": "stream", "text": [ - "[1, 10] loss: 0.00551\n", - "[1, 20] loss: 0.00548\n", - "[1, 30] loss: 0.00579\n", - "[1, 40] loss: 0.00569\n", - "[1, 50] loss: 0.00576\n", - "[1, 60] loss: 0.00576\n", - "[1, 70] loss: 0.00548\n", - "[1, 80] loss: 0.0056\n", - "[1, 90] loss: 0.00585\n", - "[1, 100] loss: 0.00578\n", - "[1, 110] loss: 0.00574\n", - "[1, 120] loss: 0.00556\n", - "[1, 130] loss: 0.00574\n", - "[1, 140] loss: 0.00562\n", - "[1, 150] loss: 0.00566\n", - "[1, 160] loss: 0.00564\n", - "[1, 170] loss: 0.00558\n", - "[1, 180] loss: 0.00554\n", - "[1, 190] loss: 0.00554\n", - "[1, 200] loss: 0.00561\n", - "[2, 10] loss: 0.00551\n", - "[2, 20] loss: 0.00548\n", - "[2, 30] loss: 0.00579\n", - "[2, 40] loss: 0.00569\n", - "[2, 50] loss: 0.00576\n", - "[2, 60] loss: 0.00576\n", - "[2, 70] loss: 0.00548\n", - "[2, 80] loss: 0.0056\n", - "[2, 90] loss: 0.00585\n", - "[2, 100] loss: 0.00578\n", - "[2, 110] loss: 0.00574\n", - "[2, 120] loss: 0.00556\n", - "[2, 130] loss: 0.00574\n", - "[2, 140] loss: 0.00562\n", - "[2, 150] loss: 0.00566\n", - "[2, 160] loss: 0.00564\n", - "[2, 170] loss: 0.00558\n", - "[2, 180] loss: 0.00554\n", - "[2, 190] loss: 0.00554\n", - "[2, 200] loss: 0.00561\n", - "[3, 10] loss: 0.00551\n", - "[3, 20] loss: 0.00548\n", - "[3, 30] loss: 0.00579\n", - "[3, 40] loss: 0.00569\n", - "[3, 50] loss: 0.00576\n", - "[3, 60] loss: 0.00576\n", - "[3, 70] loss: 0.00548\n", - "[3, 80] loss: 0.0056\n", - "[3, 90] loss: 0.00585\n", - "[3, 100] loss: 0.00578\n", - "[3, 110] loss: 0.00574\n", - "[3, 120] loss: 0.00556\n", - "[3, 130] loss: 0.00574\n", - "[3, 140] loss: 0.00562\n", - "[3, 150] loss: 0.00566\n", - "[3, 160] loss: 0.00564\n", - "[3, 170] loss: 0.00558\n", - "[3, 180] loss: 0.00554\n", - "[3, 190] loss: 0.00554\n", - "[3, 200] loss: 0.00561\n", - "[4, 10] loss: 0.00551\n", - "[4, 20] loss: 0.00548\n", - "[4, 30] loss: 0.00579\n", - "[4, 40] loss: 0.00569\n", - "[4, 50] loss: 0.00576\n", - "[4, 60] loss: 0.00576\n", - "[4, 70] loss: 0.00548\n", - "[4, 80] loss: 0.0056\n", - "[4, 90] loss: 0.00585\n", - "[4, 100] loss: 0.00578\n", - "[4, 110] loss: 0.00574\n", - "[4, 120] loss: 0.00556\n", - "[4, 130] loss: 0.00574\n", - "[4, 140] loss: 0.00562\n", - "[4, 150] loss: 0.00566\n", - "[4, 160] loss: 0.00564\n", - "[4, 170] loss: 0.00558\n", - "[4, 180] loss: 0.00554\n", - "[4, 190] loss: 0.00554\n", - "[4, 200] loss: 0.00561\n", - "[5, 10] loss: 0.00551\n", - "[5, 20] loss: 0.00548\n", - "[5, 30] loss: 0.00579\n", - "[5, 40] loss: 0.00569\n", - "[5, 50] loss: 0.00576\n", - "[5, 60] loss: 0.00576\n", - "[5, 70] loss: 0.00548\n", - "[5, 80] loss: 0.0056\n", - "[5, 90] loss: 0.00585\n", - "[5, 100] loss: 0.00578\n", - "[5, 110] loss: 0.00574\n", - "[5, 120] loss: 0.00556\n", - "[5, 130] loss: 0.00574\n", - "[5, 140] loss: 0.00562\n", - "[5, 150] loss: 0.00566\n", - "[5, 160] loss: 0.00564\n", - "[5, 170] loss: 0.00558\n", - "[5, 180] loss: 0.00554\n", - "[5, 190] loss: 0.00554\n", - "[5, 200] loss: 0.00561\n", + "[1, 10] loss: 0.00593\n", + "[1, 20] loss: 0.00591\n", + "[1, 30] loss: 0.00607\n", + "[1, 40] loss: 0.00602\n", + "[1, 50] loss: 0.00605\n", + "[1, 60] loss: 0.00605\n", + "[1, 70] loss: 0.00591\n", + "[1, 80] loss: 0.00597\n", + "[1, 90] loss: 0.0061\n", + "[1, 100] loss: 0.00606\n", + "[1, 110] loss: 0.00604\n", + "[1, 120] loss: 0.00595\n", + "[1, 130] loss: 0.00604\n", + "[1, 140] loss: 0.00598\n", + "[1, 150] loss: 0.006\n", + "[1, 160] loss: 0.00599\n", + "[1, 170] loss: 0.00596\n", + "[1, 180] loss: 0.00594\n", + "[1, 190] loss: 0.00594\n", + "[1, 200] loss: 0.00598\n", + "[2, 10] loss: 0.00593\n", + "[2, 20] loss: 0.00591\n", + "[2, 30] loss: 0.00607\n", + "[2, 40] loss: 0.00602\n", + "[2, 50] loss: 0.00605\n", + "[2, 60] loss: 0.00605\n", + "[2, 70] loss: 0.00591\n", + "[2, 80] loss: 0.00597\n", + "[2, 90] loss: 0.0061\n", + "[2, 100] loss: 0.00606\n", + "[2, 110] loss: 0.00604\n", + "[2, 120] loss: 0.00595\n", + "[2, 130] loss: 0.00604\n", + "[2, 140] loss: 0.00598\n", + "[2, 150] loss: 0.006\n", + "[2, 160] loss: 0.00599\n", + "[2, 170] loss: 0.00596\n", + "[2, 180] loss: 0.00594\n", + "[2, 190] loss: 0.00594\n", + "[2, 200] loss: 0.00598\n", + "[3, 10] loss: 0.00593\n", + "[3, 20] loss: 0.00591\n", + "[3, 30] loss: 0.00607\n", + "[3, 40] loss: 0.00602\n", + "[3, 50] loss: 0.00605\n", + "[3, 60] loss: 0.00605\n", + "[3, 70] loss: 0.00591\n", + "[3, 80] loss: 0.00597\n", + "[3, 90] loss: 0.0061\n", + "[3, 100] loss: 0.00606\n", + "[3, 110] loss: 0.00604\n", + "[3, 120] loss: 0.00595\n", + "[3, 130] loss: 0.00604\n", + "[3, 140] loss: 0.00598\n", + "[3, 150] loss: 0.006\n", + "[3, 160] loss: 0.00599\n", + "[3, 170] loss: 0.00596\n", + "[3, 180] loss: 0.00594\n", + "[3, 190] loss: 0.00594\n", + "[3, 200] loss: 0.00598\n", + "[4, 10] loss: 0.00593\n", + "[4, 20] loss: 0.00591\n", + "[4, 30] loss: 0.00607\n", + "[4, 40] loss: 0.00602\n", + "[4, 50] loss: 0.00605\n", + "[4, 60] loss: 0.00605\n", + "[4, 70] loss: 0.00591\n", + "[4, 80] loss: 0.00597\n", + "[4, 90] loss: 0.0061\n", + "[4, 100] loss: 0.00606\n", + "[4, 110] loss: 0.00604\n", + "[4, 120] loss: 0.00595\n", + "[4, 130] loss: 0.00604\n", + "[4, 140] loss: 0.00598\n", + "[4, 150] loss: 0.006\n", + "[4, 160] loss: 0.00599\n", + "[4, 170] loss: 0.00596\n", + "[4, 180] loss: 0.00594\n", + "[4, 190] loss: 0.00594\n", + "[4, 200] loss: 0.00598\n", + "[5, 10] loss: 0.00593\n", + "[5, 20] loss: 0.00591\n", + "[5, 30] loss: 0.00607\n", + "[5, 40] loss: 0.00602\n", + "[5, 50] loss: 0.00605\n", + "[5, 60] loss: 0.00605\n", + "[5, 70] loss: 0.00591\n", + "[5, 80] loss: 0.00597\n", + "[5, 90] loss: 0.0061\n", + "[5, 100] loss: 0.00606\n", + "[5, 110] loss: 0.00604\n", + "[5, 120] loss: 0.00595\n", + "[5, 130] loss: 0.00604\n", + "[5, 140] loss: 0.00598\n", + "[5, 150] loss: 0.006\n", + "[5, 160] loss: 0.00599\n", + "[5, 170] loss: 0.00596\n", + "[5, 180] loss: 0.00594\n", + "[5, 190] loss: 0.00594\n", + "[5, 200] loss: 0.00598\n", "\n", "Finished Training\n", "Testing accuracy on unseen data...\n", @@ -1563,7 +1563,7 @@ } ], "source": [ - "net2 = Net()\n", + "net2 = Net().to(device)\n", "# Define Optimizer. In this case, we will use Stochastic Gradient Descent\n", "optimizer = optim.SGD(net2.parameters(), lr=learning_rate, momentum=momentum)\n", "model = train(net, x_train, y_train, criterion, optimizer, n_epochs=5)\n", @@ -1584,11 +1584,11 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 19, "metadata": { "ExecuteTime": { - "end_time": "2020-10-13T05:22:54.896392Z", - "start_time": "2020-10-13T05:22:54.886794Z" + "end_time": "2020-10-13T05:57:46.604546Z", + "start_time": "2020-10-13T05:57:46.595221Z" } }, "outputs": [], @@ -1647,17 +1647,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "ExecuteTime": { - "start_time": "2020-10-13T05:22:55.453Z" - } + "end_time": "2020-10-13T05:58:30.756771Z", + "start_time": "2020-10-13T05:58:20.999118Z" + }, + "scrolled": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "b7ba80bc3839404a9abff6be6e8cfbad", + "model_id": "87d07c458f3b4b41a4efe0eeaa7736db", "version_major": 2, "version_minor": 0 }, @@ -1672,33 +1674,32 @@ "name": "stdout", "output_type": "stream", "text": [ - "[1, 10] loss: 0.0716\n", - "[1, 20] loss: 0.0141\n", - "[1, 30] loss: 0.00412\n", - "[1, 40] loss: 0.00163\n", - "[1, 50] loss: 0.000968\n", - "[1, 60] loss: 0.000379\n", - "[1, 70] loss: 0.000479\n", - "[1, 80] loss: 0.000297\n", - "[1, 90] loss: 0.000309\n", - "[1, 100] loss: 0.000187\n", - "[1, 110] loss: 0.000177\n", - "[1, 120] loss: 0.000107\n", - "[1, 130] loss: 0.00012\n", - "[1, 140] loss: 6.42e-05\n", - "[1, 150] loss: 7.21e-05\n", - "[1, 160] loss: 5.12e-05\n", - "[1, 170] loss: 0.000135\n", - "[1, 180] loss: 4.67e-05\n", - "[1, 190] loss: 0.000169\n", - "[1, 200] loss: 0.000174\n", - "\n", - "Finished Training\n" + "[1, 10] loss: 0.0575\n", + "[1, 20] loss: 0.00931\n", + "[1, 30] loss: 0.00228\n", + "[1, 40] loss: 0.00118\n", + "[1, 50] loss: 0.000458\n", + "[1, 60] loss: 0.000296\n", + "[1, 70] loss: 0.000515\n", + "[1, 80] loss: 0.000351\n", + "\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mconvnet\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBetterCNN\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0moptimizer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptim\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAdam\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconvnet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparameters\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlearning_rate\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconvnet\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcriterion\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptimizer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx_test\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mtrain\u001b[0;34m(model, x, y, criterion, optimizer, n_epochs, bs)\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;31m# print statistics\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[0mrunning_loss\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitem\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 25\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;36m10\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m9\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"[%d, %5d] loss: %.3g\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mepoch\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrunning_loss\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m2000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ - "convnet = BetterCNN()\n", + "convnet = BetterCNN().to(device)\n", "optimizer = torch.optim.Adam(convnet.parameters(), lr=learning_rate)\n", "model = train(convnet, x_train, y_train, criterion, optimizer)\n", "test(model, x_test, y_test)" @@ -1706,13 +1707,80 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 22, + "metadata": { + "ExecuteTime": { + "end_time": "2020-10-13T05:58:31.862332Z", + "start_time": "2020-10-13T05:58:31.829274Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "================================================================================\n", + " Kernel Shape Output Shape Params \\\n", + "Layer \n", + "0_layer1.Conv2d_0 [1, 32, 3, 3] [1, 32, 99, 99] 320.0 \n", + "1_layer1.BatchNorm2d_1 [32] [1, 32, 99, 99] 64.0 \n", + "2_layer1.ReLU_2 - [1, 32, 99, 99] - \n", + "3_layer1.MaxPool2d_3 - [1, 32, 49, 49] - \n", + "4_layer2.Conv2d_0 [32, 64, 3, 3] [1, 64, 47, 47] 18.496k \n", + "5_layer2.BatchNorm2d_1 [64] [1, 64, 47, 47] 128.0 \n", + "6_layer2.ReLU_2 - [1, 64, 47, 47] - \n", + "7_layer2.MaxPool2d_3 - [1, 64, 23, 23] - \n", + "8_layer3.Conv2d_0 [64, 128, 3, 3] [1, 128, 21, 21] 73.856k \n", + "9_layer3.BatchNorm2d_1 [128] [1, 128, 21, 21] 256.0 \n", + "10_layer3.ReLU_2 - [1, 128, 21, 21] - \n", + "11_layer3.MaxPool2d_3 - [1, 128, 10, 10] - \n", + "12_fc1 [12800, 512] [1, 512] 6.554112M \n", + "13_drop - [1, 512] - \n", + "14_fc2 [512, 128] [1, 128] 65.664k \n", + "15_fc3 [128, 4] [1, 4] 516.0 \n", + "\n", + " Mult-Adds \n", + "Layer \n", + "0_layer1.Conv2d_0 2.822688M \n", + "1_layer1.BatchNorm2d_1 32.0 \n", + "2_layer1.ReLU_2 - \n", + "3_layer1.MaxPool2d_3 - \n", + "4_layer2.Conv2d_0 40.716288M \n", + "5_layer2.BatchNorm2d_1 64.0 \n", + "6_layer2.ReLU_2 - \n", + "7_layer2.MaxPool2d_3 - \n", + "8_layer3.Conv2d_0 32.514048M \n", + "9_layer3.BatchNorm2d_1 128.0 \n", + "10_layer3.ReLU_2 - \n", + "11_layer3.MaxPool2d_3 - \n", + "12_fc1 6.5536M \n", + "13_drop - \n", + "14_fc2 65.536k \n", + "15_fc3 512.0 \n", + "--------------------------------------------------------------------------------\n", + " Totals\n", + "Total params 6.713412M\n", + "Trainable params 6.713412M\n", + "Non-trainable params 0.0\n", + "Mult-Adds 82.672896M\n", + "================================================================================\n" + ] + }, + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from deep_ml_curriculum.torchsummaryX import summary\n", "# We can also summarise the number of parameters in each layer\n", - "summary(net, torch.rand((1, 1, 99, 99)))\n", + "summary(convnet, torch.rand((1, 1, 99, 99)).to(device))\n", "1" ] }, @@ -1742,7 +1810,7 @@ " \n", "```python\n", "learning_rate = 1e-3\n", - "convnet2 = BetterCNN()\n", + "convnet2 = BetterCNN().to(device)\n", "optimizer = torch.optim.Adam(convnet2.parameters(), lr=learning_rate)\n", "model = train(convnet2, x_train, y_train, criterion, optimizer, n_epochs=10)\n", "test(model, x_test, y_test)\n", @@ -1751,6 +1819,51 @@ "" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-10-13T05:58:42.602Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "90b0f467dd314fb4830cf6a3e19bf5a0", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=10.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 10] loss: 0.0537\n", + "[1, 20] loss: 0.00856\n", + "[1, 30] loss: 0.0023\n", + "[1, 40] loss: 0.000716\n", + "[1, 50] loss: 0.00039\n", + "[1, 60] loss: 0.000216\n", + "[1, 70] loss: 0.000143\n" + ] + } + ], + "source": [ + "learning_rate = 1e-3\n", + "convnet2 = BetterCNN().to(device)\n", + "optimizer = torch.optim.Adam(convnet2.parameters(), lr=learning_rate)\n", + "model = train(convnet2, x_train, y_train, criterion, optimizer, n_epochs=10)\n", + "test(model, x_test, y_test)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -1761,7 +1874,12 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2020-10-13T05:57:46.993651Z", + "start_time": "2020-10-13T05:57:00.198Z" + } + }, "outputs": [], "source": [ "# Now that we finished the training let's save our best model\n", diff --git a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py index 667fae3..fd48d83 100644 --- a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py +++ b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py @@ -126,6 +126,8 @@ # # We will train a CNN to learn how to classify images into those 4 groups. +device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") + # + # Let's import the Patches from deep_ml_curriculum.data.landmass_f3 import LandmassF3Patches @@ -213,12 +215,12 @@ def num_flat_features(self, x): # Create an instance of your network -net = Net() +net = Net().to(device) print(net) from deep_ml_curriculum.torchsummaryX import summary # We can also summarise the number of parameters in each layer -summary(net, torch.rand((1, 1, 99, 99))) +summary(net, torch.rand((1, 1, 99, 99)).to(device)) 1 # Let's try a random 99x99 input. The input image to follow this convention: @@ -231,7 +233,7 @@ def num_flat_features(self, x): # # + -input = torch.rand(1, 1, 99, 99) +input = torch.rand(1, 1, 99, 99).to(device) out = net(input) # An array with 4 output, each one corresponding to @@ -287,8 +289,8 @@ def train(model, x, y, criterion, optimizer, n_epochs=1, bs=64): # Let's divide the data in batches start_i = i * bs end_i = start_i + bs - inputs = x_train[start_i:end_i].unsqueeze(1).float() - labels = y_train[start_i:end_i].long() + inputs = x_train[start_i:end_i].unsqueeze(1).float().to(device) + labels = y_train[start_i:end_i].long().to(device) # zero the parameter gradients optimizer.zero_grad() @@ -316,7 +318,7 @@ def test(model, x, y): total = 0 for idx, image in enumerate(x): - pred = model(image.unsqueeze(0).unsqueeze(0)).argmax() + pred = model(image.unsqueeze(0).unsqueeze(0).cuda()).argmax() if int(pred) == int(y[idx]): correct += 1 total += 1 @@ -334,7 +336,7 @@ def test(model, x, y): # Let's try again with 1 more epochs... -net2 = Net() +net2 = Net().to(device) # Define Optimizer. In this case, we will use Stochastic Gradient Descent optimizer = optim.SGD(net2.parameters(), lr=learning_rate, momentum=momentum) model = train(net, x_train, y_train, criterion, optimizer, n_epochs=5) @@ -396,14 +398,14 @@ def forward(self, x): # Let's see first the results training the new model using only 1 epoch. -convnet = BetterCNN() +convnet = BetterCNN().to(device) optimizer = torch.optim.Adam(convnet.parameters(), lr=learning_rate) model = train(convnet, x_train, y_train, criterion, optimizer) test(model, x_test, y_test) from deep_ml_curriculum.torchsummaryX import summary # We can also summarise the number of parameters in each layer -summary(net, torch.rand((1, 1, 99, 99))) +summary(convnet, torch.rand((1, 1, 99, 99)).to(device)) 1 #
@@ -423,7 +425,7 @@ def forward(self, x): # # ```python # learning_rate = 1e-3 -# convnet2 = BetterCNN() +# convnet2 = BetterCNN().to(device) # optimizer = torch.optim.Adam(convnet2.parameters(), lr=learning_rate) # model = train(convnet2, x_train, y_train, criterion, optimizer, n_epochs=10) # test(model, x_test, y_test) @@ -431,6 +433,12 @@ def forward(self, x): # # +learning_rate = 1e-3 +convnet2 = BetterCNN().to(device) +optimizer = torch.optim.Adam(convnet2.parameters(), lr=learning_rate) +model = train(convnet2, x_train, y_train, criterion, optimizer, n_epochs=10) +test(model, x_test, y_test) + # Finally ! After changing the optimizer, creating a better CNN architecture and train for a couple of epochs we got an accuracy of over 99% on unseen data. # +