forked from setarehc/bmiai-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMNIST+CNN_source.ipynb
666 lines (666 loc) · 55.6 KB
/
MNIST+CNN_source.ipynb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Task\n",
"In this tutorial, we will classify the MNIST dataset using a Convolutional Neural Network (CNN)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Import libraries"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before anything, let's import some basic libraries:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import torch\n",
"import torchvision\n",
"import torchvision.transforms as transforms\n",
"import torch.nn as nn\n",
"import torch.nn.functional as F\n",
"import torch.optim as optim\n",
"from torch.utils.data import DataLoader\n",
"from torch.utils.data import Dataset\n",
"import matplotlib\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Preparation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Training and test set should be first loaded from the folder containing our data, as was done in the previous tutorial:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Load the data:\n",
"train = pd.read_csv('data/train.csv')\n",
"test = pd.read_csv('data/test.csv')\n",
"\n",
"# Split the data into features and labels for each image:\n",
"Y_train = train[\"label\"]\n",
"X_train = train.drop(labels=\"label\",axis=1)\n",
"X_test = test\n",
"\n",
"# Normalize values:\n",
"X_train = X_train/255.0\n",
"test = test/255.0\n",
"\n",
"# Reshape the pixels to their original 28x28 format:\n",
"X_train, Y_train = X_train.values.reshape(-1, 28,28), Y_train.values\n",
"X_test = X_test.values.reshape(-1,28,28)\n",
"\n",
"# Split into training and validation:\n",
"X_valid, Y_valid = X_train[-2000:], Y_train[-2000:]\n",
"X_train, Y_train = X_train[:-2000], Y_train[:-2000]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PyTorch provides some helper functions to load data, shuffle, and augment. Dataset and DataLoader are two of these functions.\n",
"\n",
"So let's create a class that is inherited from the Dataset class. This class provides functions to gather data and also to know the number of items:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"class MNISTDataset(Dataset):\n",
" def __init__(self, X, Y=None):\n",
" super().__init__()\n",
" self.X = X\n",
" self.Y = Y\n",
" \n",
" def __getitem__(self, index):\n",
" if self.Y is None:\n",
" return self.X[index]\n",
" return self.X[index], self.Y[index]\n",
" \n",
" def __len__(self):\n",
" return len(self.X)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next step will be to instantiate the dataset to then pass it to the DataLoader. By using the DataLoader, pytorch will manage for you all the shuffling management and loading (multi-threaded) of the data:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"trainset = MNISTDataset(X_train, Y_train)\n",
"testset = MNISTDataset(X_test)\n",
"validset = MNISTDataset(X_valid, Y_valid)\n",
"\n",
"# batch_size=how many samples per batch to load\n",
"# num_workers= how many subprocesses to use for data loading\n",
"trainloader = DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)\n",
"testloader = DataLoader(testset, batch_size=4, shuffle=False, num_workers=2)\n",
"validloader = DataLoader(validset, batch_size=4, shuffle=False)\n",
"\n",
"classes = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now pytorch will manage for you all the shuffling management and loading (multi-threaded) of your data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's see some of the training samples and their labels available through trainloader:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADXVJREFUeJzt3X+IXfWZx/HPx9kmSBowUkyCzZoa\nwrJV2EQGEbOIUhLcTSEWjMZAzdLaabTBDSz+IP5RYSnEZROtIJWExEZoTQrGzVDqtkGXdSuL+aVG\nm2xbCWM7myFTEyHTv4Lx2T/mZBnj3HMn9557z5087xfIvfc895zzcM1nzjn3nHO/jggByOeKuhsA\nUA/CDyRF+IGkCD+QFOEHkiL8QFKEH0iK8ANJEX4gqb/o5spsczkh0GER4am8r60tv+07bf/W9ge2\nH29nWQC6y61e22+7T9LvJC2XNCzpoKT7IuJYyTxs+YEO68aW/2ZJH0TEiYg4J2m3pFVtLA9AF7UT\n/msl/XHC6+Fi2mfYHrB9yPahNtYFoGLtfOE32a7F53brI2KbpG0Su/1AL2lnyz8sacGE11+WdLK9\ndgB0SzvhPyhpse2v2J4haY2kwWraAtBpLe/2R8QntjdI+qWkPkk7I+I3lXUGoKNaPtXX0so45gc6\nrisX+QCYvgg/kBThB5Ii/EBShB9IivADSRF+ICnCDyRF+IGkCD+QFOEHkiL8QFKEH0iK8ANJEX4g\nKcIPJEX4gaQIP5AU4QeSIvxAUoQfSIrwA0kRfiApwg8kRfiBpAg/kBThB5Ii/EBShB9IquUhuiXJ\n9pCkMUnnJX0SEf1VNAVMxez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uTtv+3+Ozesf33NfW2wPZ/2D5u+ze2/7GYXutnV9JX\nLZ9b13f7bfdJ+p2k5ZKGJR2UdF9EHOtqIw3YHpLUHxG1nxO2fZukP0t68cJoSLb/RdKZiNhc/OGc\nExGP9UhvT+oSR27uUG+NRpb+B9X42VU54nUV6tjy3yzpg4g4ERHnJO2WtKqGPnpeRLwh6cxFk1dJ\n2lU836Xxfzxd16C3nhARIxFxpHg+JunCyNK1fnYlfdWijvBfK+mPE14Pq7eG/A5Jv7J92PZA3c1M\nYu6FkZGKx2tq7udiTUdu7qaLRpbumc+ulRGvq1ZH+CcbTaSXTjksi4ibJP2dpO8Vu7eYmh9JWqTx\nYdxGJG2ps5liZOmXJW2MiLN19jLRJH3V8rnVEf5hSQsmvP6ypJM19DGpiDhZPI5KekXjhym95NSF\nQVKLx9Ga+/l/EXEqIs5HxKeStqvGz64YWfplST+JiL3F5No/u8n6qutzqyP8ByUttv0V2zMkrZE0\nWEMfn2N7VvFFjGzPkrRCvTf68KCkdcXzdZL21djLZ/TKyM2NRpZWzZ9dr414XctFPsWpjGck9Una\nGRE/6HoTk7B9vca39tL4HY8/rbM32y9Jul3jd32dkvR9Sf8m6WeS/lLSHyStjoiuf/HWoLfbdYkj\nN3eot0YjS7+lGj+7Kke8rqQfrvADcuIKPyApwg8kRfiBpAg/kBThB5Ii/EBShB9IivADSf0fYqL+\njySWVMsAAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x11fd47550>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Label: 4\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5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/TDGy9EDodsTrqjUR/gOSFkx6/UVJBxvoY0oRcbB4PCJpiwZv9OHDpwdJ\nLR6PNNzPPwzSyM1TjSytAdh2gzTidRPhf1nSlba/ZHu2pG9I2tZAH59ie07xhxjZniPpaxq80Ye3\nSVpZPF8paWuDvXzCoIzc3GpkaTW87QZtxOtGLvIpTmU8JmlI0rqIeKjvTUzB9j9pYm8vTXzj8edN\n9mZ7o6QlmvjW12FJP5D0X5I2SbpM0p8l3R4Rff/DW4velugsR26uqbdWI0u/pAa3XZUjXlfSD1f4\nATlxhR+QFOEHkiL8QFKEH0iK8ANJEX4gKcIPJEX4gaT+H/W/30NVNfZ5AAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x1013bbb00>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Label: 9\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADd1JREFUeJzt3X+MFfW5x/HPgxQhFKMbRNBuL5WY\nptdf9GYjTYpG01C8poj9Ayx/GNSm28QabKyJxESLyd6kMdiWP7Rmm5JibIVGW8XEKIY0QvVKWExF\nCoVCw20RstuKSSHiVvTpHzvcbHHPdw7nzJyZ5Xm/ErLnnOfMzJMTPjtz9jszX3N3AYhnQtUNAKgG\n4QeCIvxAUIQfCIrwA0ERfiAowg8ERfiBoAg/ENTETm7MzDidECiZu1sz72trz29mN5rZXjPbb2Yr\n21kXgM6yVs/tN7NzJO2TtEDSIUnbJS1z992JZdjzAyXrxJ7/Gkn73f3P7v5PSeslLW5jfQA6qJ3w\nXyLpr6OeH8pe+zdm1mtmA2Y20Ma2ABSsn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nI3t7aeSKx19W2ZuZPS3peo1c9TUo6fuSnpP0K0mflfQXSUvcveN/eGvQ2/U6w5mbS+qt0czS21Th\nZ1fkjNeF9MMZfkBMnOEHBEX4gaAIPxAU4QeCIvxAUIQfCIrwA0ERfiCofwGccB9uKwX9UAAAAABJ\nRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10e932080>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Label: 5\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADNNJREFUeJzt3W2IXOUZxvHrqjV+SKtRiuliU2NL\nLA0RbVlitaVaq2IlEAWV5lNE6fZDhQQqKCJUKIUibbSfCqnGpJD6htqEUJpE8SWFYowi1TZ9MSFN\nt7vsVhJogkJIvPthT8qa7JyZnTlnzmzu/w/CzJx7Zp6bIdc+Z+acmccRIQD5fKLpBgA0g/ADSRF+\nICnCDyRF+IGkCD+QFOEHkiL8QFKEH0jqk/0czDanEwI1iwh3cr+eZn7bN9n+m+33bN/fy3MB6C93\ne26/7bMk/V3SDZJGJb0haVVE/KXkMcz8QM36MfMvl/ReROyPiGOSnpK0sofnA9BHvYT/Ikn/mnZ7\ntNj2MbZHbO+xvaeHsQBUrJcP/GbatThttz4i1ktaL7HbDwySXmb+UUmLpt3+nKSx3toB0C+9hP8N\nSUtsX2J7nqTvStpaTVsA6tb1bn9EHLd9j6Ttks6StCEi/lxZZwBq1fWhvq4G4z0/ULu+nOQDYO4i\n/EBShB9IivADSRF+ICnCDyRF+IGkCD+QFOEHkiL8QFKEH0iK8ANJEX4gKcIPJEX4gaQIP5AU4QeS\n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1JqyLiL31tpAXbByQNR0Tjx4Rtf1PSUUm/Prkaku2H\nJR2KiJ8WfzjPj4j7BqS3hzTLlZtr6q3VytJ3qsHXrsoVr6vQxMy/XNJ7EbE/Io5JekrSygb6GHgR\n8ZqkQ6dsXilpU3F9k6b+8/Rdi94GQkSMR8RbxfUjkk6uLN3oa1fSVyOaCP9Fkv417faoBmvJ75C0\nw/abtkeabmYGC0+ujFRcXthwP6dqu3JzP52ysvTAvHbdrHhdtSbCP9NqIoN0yOHrEfFVSd+R9INi\n9xad+aWkL2pqGbdxST9vspliZennJK2NiP822ct0M/TVyOvWRPhHJS2advtzksYa6GNGETFWXE5K\nekFTb1MGycTJRVKLy8mG+/m/iJiIiBMR8ZGkX6nB165YWfo5SZsj4vlic+Ov3Ux9NfW6NRH+NyQt\nsX2J7XmSvitpawN9nMb2/OKDGNmeL+lGDd7qw1slrS6ur5a0pcFePmZQVm5utbK0Gn7tBm3F60ZO\n8ikOZTwq6SxJGyLiJ31vYga2v6Cp2V6a+sbjb5rszfaTkq7V1Le+JiT9SNJvJT0j6fOSDkq6PSL6\n/sFbi96u1SxXbq6pt1YrS7+uBl+7Kle8rqQfzvADcuIMPyApwg8kRfiBpAg/kBThB5Ii/EBShB9I\nivADSf0PBuXBqbXzMfMAAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x11949b9e8>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Label: 1\n"
]
}
],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"for i, data in enumerate(trainloader):\n",
" imgs, labels = data\n",
" plt.figure()\n",
" two_d = (np.reshape(imgs[0].numpy()*255, (28, 28))).astype(np.uint8)\n",
" plt.imshow(two_d, cmap='gray')\n",
" plt.show()\n",
" print(\"Label: \", classes[labels[0]])\n",
" if i >= 3:\n",
" break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Defining a CNN"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Architecture of the convolutional neural network we will be using today, looks like below:\n",
"<img src=\"MNIST.png\">\n",
"\n",
"First, we have a convolutional layer with 10 filters of filter size 5$*$5, stride 1 and padding 0 followed by a ReLU layer. Following, is a Maxpool layer with filter size and stride set to 2. Next, is a convolutional layer with 20 fitlers of size 5$*$5, stride 1 and padding 0 followed by a ReLU layer. After that, is a Maxpool layer with size and stride set to 2. Last, we have a Fully connected layer with 50 output neurons followed by a ReLU layer, followed by a fully connected layer with 10 output neurons."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class CNN(nn.Module):\n",
" def __init__(self):\n",
" super(CNN, self).__init__()\n",
" self.conv1 = nn.Conv2d(1, 10, 5) # stride=1, number of filters=10, filter size=5\n",
" self.pool = nn.MaxPool2d(2,2) # stride=2, filter size=2\n",
" self.conv2 = nn.Conv2d(10, 20, 5) #stride=1, number of filters=20, filter size=5 \n",
" self.fc1 = nn.Linear(20*4*4, 50) # fully connected layer with input size 4x4x20 and output size 50\n",
" self.fc2 = nn.Linear(50, 10) # fully connected layer with input size 50 and output size 10 \n",
" \n",
" def forward(self, x):\n",
" x = x.unsqueeze(1)\n",
" x = x.float()\n",
" a1 = self.pool(F.relu(self.conv1(x)))\n",
" a2 = self.pool(F.relu(self.conv2(a1)))\n",
" a3 = a2.view(-1, 20*4*4)\n",
" a4 = F.relu(self.fc1(a3))\n",
" a5 = self.fc2(a4)\n",
" return a5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's build a model and see what it looks like:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CNN(\n",
" (conv1): Conv2d(1, 10, kernel_size=(5, 5), stride=(1, 1))\n",
" (pool): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n",
" (conv2): Conv2d(10, 20, kernel_size=(5, 5), stride=(1, 1))\n",
" (fc1): Linear(in_features=320, out_features=50, bias=True)\n",
" (fc2): Linear(in_features=50, out_features=10, bias=True)\n",
")"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cnn = CNN()\n",
"cnn"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Defining the Loss Function and the Optimizer"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We need to define the loss function and optimizer we will use to train our network. For loss function, we will use the Cross Entropy loss which is available via the torch.nn package. For optimizer, we will use the Stochastic Gradient Descent which is available via torch.nn package. The learning rate used for training is set to 0.01: "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"learning_rate = 0.01\n",
"criterion = nn.CrossEntropyLoss()\n",
"optimizer = optim.SGD(cnn.parameters(), lr=learning_rate, momentum=0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Training the Network"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's define a function for training the network:\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def train(model, optimizer=optimizer, criterion=criterion, learning_rate=learning_rate, epochs=5):\n",
" losses = []\n",
" for epoch in range(epochs):\n",
" for i, data in enumerate(trainloader):\n",
" samples, labels = data\n",
"\n",
" # Zero the parameter gradients\n",
" optimizer.zero_grad()\n",
"\n",
" predictions = model(samples)\n",
" loss = criterion(predictions, labels)\n",
" loss.backward()\n",
" optimizer.step()\n",
"\n",
" # Print some statistics\n",
" if i % 2000 == 1999:\n",
" losses.append(loss.data.mean())\n",
" print('epoch[%d], mini-batch[%5d] loss: %.3f' % (epoch+1, i+1, np.mean(losses)))\n",
" total_loss = 0 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can train our CNN model, \"cnn\" using the \"train\" function as below: "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"epoch[1], mini-batch[ 2000] loss: 0.090\n",
"epoch[1], mini-batch[ 4000] loss: 0.097\n",
"epoch[1], mini-batch[ 6000] loss: 0.065\n",
"epoch[1], mini-batch[ 8000] loss: 0.053\n",
"epoch[1], mini-batch[10000] loss: 0.050\n",
"epoch[2], mini-batch[ 2000] loss: 0.042\n",
"epoch[2], mini-batch[ 4000] loss: 0.048\n",
"epoch[2], mini-batch[ 6000] loss: 0.042\n",
"epoch[2], mini-batch[ 8000] loss: 0.038\n",
"epoch[2], mini-batch[10000] loss: 0.090\n",
"epoch[3], mini-batch[ 2000] loss: 0.082\n",
"epoch[3], mini-batch[ 4000] loss: 0.075\n",
"epoch[3], mini-batch[ 6000] loss: 0.070\n",
"epoch[3], mini-batch[ 8000] loss: 0.067\n",
"epoch[3], mini-batch[10000] loss: 0.062\n",
"epoch[4], mini-batch[ 2000] loss: 0.059\n",
"epoch[4], mini-batch[ 4000] loss: 0.055\n",
"epoch[4], mini-batch[ 6000] loss: 0.052\n",
"epoch[4], mini-batch[ 8000] loss: 0.049\n",
"epoch[4], mini-batch[10000] loss: 0.047\n",
"epoch[5], mini-batch[ 2000] loss: 0.045\n",
"epoch[5], mini-batch[ 4000] loss: 0.043\n",
"epoch[5], mini-batch[ 6000] loss: 0.041\n",
"epoch[5], mini-batch[ 8000] loss: 0.040\n",
"epoch[5], mini-batch[10000] loss: 0.038\n"
]
}
],
"source": [
"train(cnn)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tip: When you train networks for deep learning, it is often useful to monitor the training progress. By plotting metrics such as loss or accuracy during training, you can learn how the training is progressing. For example, you can determine if and how quickly the network loss is decreasing, and whether the network is starting to overfit the training data. "
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Testing the Trained Network"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the validation set, we can see the accuracy of trained CNN (cnn):"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy on 2000 test images is = 98 %\n"
]
}
],
"source": [
"total = 0\n",
"corrects = 0\n",
"\n",
"for data in validloader:\n",
" images, labels = data\n",
" outputs = cnn(images)\n",
" _, predicted_lables = torch.max(outputs.data, 1)\n",
" total += labels.size(0)\n",
" corrects += (predicted_lables == labels).sum().item()\n",
"\n",
"print('Accuracy on %d test images is = %d %%' % (total, 100*corrects/total))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look at some samples in the validation set and their predicted labels:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADeVJREFUeJzt3X+o1fUdx/HXO+cMrpaKZDdruoms\nrYjMSyyUci1XG6INMRIEx2K3aMIG/TGJwCCklWtt/SM4JlOYrqLuFFltJmt3oxVdL8sfuVyMu2le\ndGVhCmXX+94f9+u42T2fc+75nu/5nuv7+QA5P97nfD9vTr3u93vO53vOx9xdAOK5qOwGAJSD8ANB\nEX4gKMIPBEX4gaAIPxAU4QeCIvxAUIQfCOpzzRzMzDidECiYu1stj8u15zezO8zsLTN728zW5NkW\ngOayes/tN7Nxkg5JWiTpiKTXJa1w9zcTz2HPDxSsGXv+GyW97e7/cvczkn4raWmO7QFoojzhnyHp\n8LDbR7L7PsXMOs2sx8x6cowFoMHyfOA30qHFZw7r3X2jpI0Sh/1AK8mz5z8i6apht6+UdDRfOwCa\nJU/4X5c0x8y+aGafl3S3pB2NaQtA0eo+7Hf3ATNbLekPksZJ2uTuBxrWGYBC1T3VV9dg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UIQfCIrwA0ERfiAowg8ERfiBoAg/EBThB4L6HwlNIA1l\neXNjAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x1195cc860>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Predicted Label: [2]\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADeNJREFUeJzt3X+MVPW5x/HPUwVNBCMLQQjgtW3w\nF0aBLGqiqd4YG9s0wZpASrDhmoYlWmOr/eMaYyz+YUIMpfYP07DophhbSyNFIWlaNsTIvaES1h8p\nChdQ2ZZVXCSisPxhoz73jz00W9zznWHmzJyzPO9XYnbmPPOd82Tks+fMfs/M19xdAOL5WtkNACgH\n4QeCIvxAUIQfCIrwA0ERfiAowg8ERfiBoAg/ENS57dyZmXE5IdBi7m71PK6pI7+Z3W5m+8zsHTN7\nqJnnAtBe1ui1/WZ2jqT9km6TNCBpl6Ql7r4nMYYjP9Bi7TjyXyfpHXd/z93/Ken3khY28XwA2qiZ\n8M+QdGjE/YFs278xsy4z6zOzvib2BaBgzfzBb7RTi6+c1rt7t6RuidN+oEqaOfIPSJo14v5MSR80\n1w6Admkm/LskzTazr5vZeEk/kLS5mLYAtFrDp/3u/rmZ3SfpL5LOkdTj7m8X1hmAlmp4qq+hnfGe\nH2i5tlzkA2DsIvxAUIQfCIrwA0ERfiAowg8ERfiBoAg/EBThB4Ii/EBQhB8IivADQRF+ICjCDwRF\n+IGgCD8QFOEHgiL8QFCEHwiK8ANBEX4gKMIPBEX4gaAIPxAU4QeCIvxAUIQfCIrwA0ERfiCohpfo\nliQz65d0QtIXkj53984imgL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ngaAIPxAU4QeCIvxAUIQfCKrdS3QflfT3EfenZNuqqKq9VbUvid4aVWRv/1HvA9v6ef6v7Nysr6rf\n7VfV3qral0RvjSqrN077gaAIPxBU2eHvLnn/KVXtrap9SfTWqFJ6K/U9P4DylH3kB1CSUsJvZreb\n2T4ze8fMHiqjhzxm1m9mu83szbKXGMuWQTtiZm+N2NZhZr1mdiD7OeoyaSX1ttLM3s9euzfN7Lsl\n9TbLzF42s71m9raZ/STbXuprl+irlNet7af9ZnaOpP2SbpM0IGmXpCXuvqetjeQws35Jne5e+pyw\nmX1L0pCkZ9396mzbE5I+dvdV2S/OSe7+3xXpbaWkobJXbs4WlJk+cmVpSXdI+i+V+Nol+lqsEl63\nMo7810l6x93fc/d/Svq9pIUl9FF57r5d0senbV4oaX12e72G//G0XU5vleDuh9399ez2CUmnVpYu\n9bVL9FWKMsI/Q9KhEfcHVK0lv13SVjN7zcy6ym5mFBefWhkp+zm15H5OV3Pl5nY6bWXpyrx2jax4\nXbQywj/aaiJVmnK40d3nS/qOpB9np7eoT10rN7fLKCtLV0KjK14XrYzwD0iaNeL+TEkflNDHqNz9\ng+znEUmbVL3VhwdPLZKa/TxScj//UqWVm0dbWVoVeO2qtOJ1GeHfJWm2mX3dzMZL+oGkzSX08RVm\ndkH2hxiZ2QWSvq3qrT68WdKy7PYySS+V2Mu/qcrKzXkrS6vk165qK16XcpFPNpXxpKRzJPW4++Nt\nb2IUZvYNDR/tpeFPPP6uzN7M7HlJt2j4U1+Dkn4u6UVJf5B0iaR/SFrk7m3/w1tOb7foDFdublFv\neStL71SJr12RK14X0g9X+AExcYUfEBThB4Ii/EBQhB8IivADQRF+ICjCDwRF+IGg/h9kwBL9zchm\nUAAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10e94aac8>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Predicted Label: [8]\n"
]
},
{
"data": {
"image/png": "iVBORw0KG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RRl+qSjDLxVl+KWiDL9UlOGXijL8UlH/A5G1zc/HYaBpAAAA\nAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10ecbcb70>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Predicted Label: [0]\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADNpJREFUeJzt3X+oXPWZx/H3Y+wFMUX8gSbGqN0i\ny6pIugQJZF2ziOIuBRWt6B9Llq2mfyhY8I8VERSWQli3des/hVRDI1ib4o81hLJtEdFdkWAi2thq\na6xJezfXxB+VKgjF5Nk/7smS6p0zN3Nn5szN836BzMx55pzzMOZzv2fmzJlvZCaS6jmh6wYkdcPw\nS0UZfqkowy8VZfilogy/VJThl4oy/FJRhl8q6sRx7iwi/DqhNGKZGfN53oJG/oi4OiJ+HRF7IuKu\nhWxL0njFoN/tj4glwG+AK4Fp4CXg5sz8Vcs6jvzSiI1j5L8U2JOZv83MPwE/Aq5ZwPYkjdFCwr8C\n+P1Rj6ebZX8mIjZExM6I2LmAfUkasoV84DfXocXnDuszcxOwCTzslybJQkb+aWDlUY/PAfYvrB1J\n47KQ8L8EXBARX4qIKeAmYNtw2pI0agMf9mfmpxFxO/BTYAmwOTN/ObTOJI3UwKf6BtqZ7/mlkRvL\nl3wkLV6GXyrK8EtFGX6pKMMvFWX4paIMv1SU4ZeKMvxSUYZfKsrwS0UZfqkowy8VZfilogy/VJTh\nl4oy/FJRhl8qyvBLRRl+qSjDLxVl+KWiDL9UlOGXijL8UlGGXyrK8EtFGX6pKMMvFTXwFN0AEbEX\n+Ag4BHyamauH0ZQWj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9DHxMvN54IPPLL4G2NLc38LsP56x69HbRMjMmcx8ubn/EXBkZulOX7uWvjrRRfhX\nAL8/6vE0kzXldwI/i4hdEbGh62bmcNaRmZGa2zM77uez+s7cPE6fmVl6Yl67QWa8HrYuwj/XbCKT\ndMphbWb+NfD3wG3N4a3m53vAl5mdxm0G+HaXzTQzSz8BfDMz/9hlL0ebo69OXrcuwj8NrDzq8TnA\n/g76mFNm7m9uDwJPMfs2ZZIcODJJanN7sON+/l9mHsjMQ5l5GPg+Hb52zczSTwCPZuaTzeLOX7u5\n+urqdesi/C8BF0TElyJiCrgJ2NZBH58TESc3H8QQEScDVzF5sw9vA9Y399cDT3fYy5+ZlJmbe80s\nTcev3aTNeN3Jl3yaUxn/ASwBNmfmt8bexBwi4i+YHe1h9orHH3bZW0Q8Bqxj9qqvA8C9wH8CPwbO\nBX4HfC0zx/7BW4/e1nGMMzePqLdeM0vvoMPXbpgzXg+lH7/hJ9XkN/ykogy/VJThl4oy/FJRhl8q\nyvBLRRl+qSjDLxX1f1WJzRjWbJ6nAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x11fe64860>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Predicted Label: [1]\n"
]
}
],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"for i, data in enumerate(validloader):\n",
" imgs, labels = data\n",
" plt.figure()\n",
" two_d = (np.reshape(imgs[0].numpy()*255, (28, 28))).astype(np.uint8)\n",
" plt.imshow(two_d, cmap='gray')\n",
" plt.show()\n",
" outputs = cnn(imgs)\n",
" _, predicted_label = torch.topk(outputs[0], 1)\n",
" print('Predicted Label:', predicted_label.numpy())\n",
" if i >= 3:\n",
" break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Coding:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are other optimizer algorithms available in torch.nn package that sometimes work better than Stochastic Gradient Descent (SGD). One of these optimizers is called Adam Optimizer (Adam). Let's know train the network using the Adam optimizer:"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Define the Adam optimizer:\n",
"Adam_optimizer = optim.Adam(cnn.parameters(), lr=learning_rate)\n",
"\n",
"# Create a new instance of CNN network to train:\n",
"# -- Your code goes here --\n",
"\n",
"# Train the network using the Adam optimizer:\n",
"#-- Your code goes here --"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Having done these, let's see the accuracy of the trained network on the validation set:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#-- Your code goes here --"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}