Import and setup

In [1]:
from scipy import io
import numpy as np
from sklearn import cross_validation as scv

# Do "python setup.py develop" or add nnet to "sys.path"
from nnet import NeuralNetBuilder
import nnet.preprocessing as pre

Load and process data

In [2]:
data_path = "../digit-dataset/train.mat"
data = io.loadmat(data_path)
data_size = len(data['train_images'][0][0])
images = np.array([data['train_images'][:,:,i].flatten() for i in xrange(data_size)])
labels = np.array([data['train_labels'][i][0] for i in xrange(data_size)])
In [3]:
train_images, validation_images, train_labels, validation_labels =\
    scv.train_test_split(images, labels, test_size=0.0, random_state=1117)

train_set_size = len(train_images)
validation_set_size = len(validation_images)

print "Train set size: {0} | Validation set size {1}" \
        .format(train_set_size, validation_set_size)
Train set size: 60000 | Validation set size 0
In [4]:
reg = pre.Normalize()

train_images = reg.fit(train_images)
validation_images = reg.transform(validation_images)

Build nets

In [5]:
import cudamat as cm

cm.cublas_init()
In [6]:
net_builder = NeuralNetBuilder()

net_builder.add_fully_connected_layer(784, 'Dummy', use_dropout=True, dropout_p=0.8,
                                                    use_max_norm=True, max_norm_c=2,
                                                    use_momentum=True, momentum=0.95)\
           .add_fully_connected_layer(1024, 'ReLU', use_dropout=True,
                                                    use_max_norm=True, max_norm_c=2,
                                                    use_momentum=True, momentum=0.95)\
           .add_fully_connected_layer(1024, 'ReLU', use_dropout=True,
                                                    use_max_norm=True, max_norm_c=2,
                                                    use_momentum=True, momentum=0.95)\
           .add_fully_connected_layer(1024, 'ReLU', use_dropout=True,
                                                    use_max_norm=True, max_norm_c=2,
                                                    use_momentum=True, momentum=0.95)\
           .add_output_layer(10, 'Sigmoid', 'CEE')\
           .add_batch_size(200)\
           .add_dynamic_step_size_lr_func(1e-2, 1e-1, 4, 1e-5)\
           .add_max_epoch_stopping_criteria(3500)\
           .add_min_improve_stopping_criteria(6, 1e-8)\
           .add_status_period(5000)

net = net_builder.build()
In [7]:
losses = net.train(train_images, train_labels)
Epoch:   0 | Iteration:   0 x 5000 | Score: 0.079566666667 | Loss:  4.7065263718 | Time elapsed: 0.01 minutes
Epoch:  16 | Iteration:   1 x 5000 | Score: 0.961666666667 | Loss:  0.2253478063 | Time elapsed: 2.40 minutes
Epoch:  33 | Iteration:   2 x 5000 | Score: 0.977466666667 | Loss:  0.1326461985 | Time elapsed: 4.75 minutes
Epoch:  50 | Iteration:   3 x 5000 | Score: 0.984816666667 | Loss:  0.0919227754 | Time elapsed: 7.11 minutes
Epoch:  66 | Iteration:   4 x 5000 | Score: 0.989550000000 | Loss:  0.0668692349 | Time elapsed: 9.45 minutes
Epoch:  83 | Iteration:   5 x 5000 | Score: 0.992516666667 | Loss:  0.0494943989 | Time elapsed: 11.81 minutes
Epoch: 100 | Iteration:   6 x 5000 | Score: 0.994800000000 | Loss:  0.0378596302 | Time elapsed: 14.17 minutes
Epoch: 116 | Iteration:   7 x 5000 | Score: 0.996000000000 | Loss:  0.0300698980 | Time elapsed: 16.51 minutes
Epoch: 133 | Iteration:   8 x 5000 | Score: 0.996950000000 | Loss:  0.0235392507 | Time elapsed: 18.87 minutes
Epoch: 150 | Iteration:   9 x 5000 | Score: 0.997633333333 | Loss:  0.0187664792 | Time elapsed: 21.22 minutes
Epoch: 166 | Iteration:  10 x 5000 | Score: 0.998166666667 | Loss:  0.0152886160 | Time elapsed: 23.53 minutes
Epoch: 183 | Iteration:  11 x 5000 | Score: 0.998516666667 | Loss:  0.0125090292 | Time elapsed: 25.89 minutes
Epoch: 200 | Iteration:  12 x 5000 | Score: 0.998800000000 | Loss:  0.0107540511 | Time elapsed: 28.25 minutes
Epoch: 216 | Iteration:  13 x 5000 | Score: 0.999033333333 | Loss:  0.0091764687 | Time elapsed: 30.60 minutes
Epoch: 233 | Iteration:  14 x 5000 | Score: 0.999133333333 | Loss:  0.0073449601 | Time elapsed: 32.96 minutes
Epoch: 250 | Iteration:  15 x 5000 | Score: 0.999433333333 | Loss:  0.0066402247 | Time elapsed: 35.32 minutes
Epoch: 266 | Iteration:  16 x 5000 | Score: 0.999500000000 | Loss:  0.0054556239 | Time elapsed: 37.67 minutes
Epoch: 283 | Iteration:  17 x 5000 | Score: 0.999583333333 | Loss:  0.0046707007 | Time elapsed: 40.03 minutes
Epoch: 300 | Iteration:  18 x 5000 | Score: 0.999633333333 | Loss:  0.0039815161 | Time elapsed: 42.39 minutes
Epoch: 316 | Iteration:  19 x 5000 | Score: 0.999666666667 | Loss:  0.0035184176 | Time elapsed: 44.74 minutes
Epoch: 333 | Iteration:  20 x 5000 | Score: 0.999750000000 | Loss:  0.0029946928 | Time elapsed: 47.10 minutes
Epoch: 350 | Iteration:  21 x 5000 | Score: 0.999800000000 | Loss:  0.0026831959 | Time elapsed: 49.46 minutes
Epoch: 366 | Iteration:  22 x 5000 | Score: 0.999783333333 | Loss:  0.0024285339 | Time elapsed: 51.78 minutes
Epoch: 383 | Iteration:  23 x 5000 | Score: 0.999866666667 | Loss:  0.0020798889 | Time elapsed: 54.09 minutes
Epoch: 400 | Iteration:  24 x 5000 | Score: 0.999850000000 | Loss:  0.0018379179 | Time elapsed: 56.40 minutes
Epoch: 416 | Iteration:  25 x 5000 | Score: 0.999850000000 | Loss:  0.0016695806 | Time elapsed: 58.70 minutes
Epoch: 433 | Iteration:  26 x 5000 | Score: 0.999916666667 | Loss:  0.0015148556 | Time elapsed: 61.02 minutes
Epoch: 450 | Iteration:  27 x 5000 | Score: 0.999916666667 | Loss:  0.0013543291 | Time elapsed: 63.33 minutes
Epoch: 466 | Iteration:  28 x 5000 | Score: 0.999966666667 | Loss:  0.0011510874 | Time elapsed: 65.63 minutes
Epoch: 483 | Iteration:  29 x 5000 | Score: 0.999950000000 | Loss:  0.0011141882 | Time elapsed: 67.95 minutes
Epoch: 500 | Iteration:  30 x 5000 | Score: 0.999950000000 | Loss:  0.0009667224 | Time elapsed: 70.27 minutes
Epoch: 516 | Iteration:  31 x 5000 | Score: 0.999933333333 | Loss:  0.0009317526 | Time elapsed: 72.57 minutes
Epoch: 533 | Iteration:  32 x 5000 | Score: 0.999950000000 | Loss:  0.0008423294 | Time elapsed: 74.88 minutes
Epoch: 550 | Iteration:  33 x 5000 | Score: 0.999950000000 | Loss:  0.0008065281 | Time elapsed: 77.19 minutes
Epoch: 566 | Iteration:  34 x 5000 | Score: 0.999966666667 | Loss:  0.0007197213 | Time elapsed: 79.49 minutes
Epoch: 583 | Iteration:  35 x 5000 | Score: 0.999983333333 | Loss:  0.0006343214 | Time elapsed: 81.81 minutes
Epoch: 600 | Iteration:  36 x 5000 | Score: 0.999983333333 | Loss:  0.0006320922 | Time elapsed: 84.12 minutes
Epoch: 616 | Iteration:  37 x 5000 | Score: 0.999983333333 | Loss:  0.0005791790 | Time elapsed: 86.41 minutes
Epoch: 633 | Iteration:  38 x 5000 | Score: 0.999966666667 | Loss:  0.0005227448 | Time elapsed: 88.73 minutes
Epoch: 650 | Iteration:  39 x 5000 | Score: 0.999983333333 | Loss:  0.0005009554 | Time elapsed: 91.04 minutes
Epoch: 666 | Iteration:  40 x 5000 | Score: 0.999983333333 | Loss:  0.0004462053 | Time elapsed: 93.33 minutes
Epoch: 683 | Iteration:  41 x 5000 | Score: 0.999983333333 | Loss:  0.0004113246 | Time elapsed: 95.65 minutes
Epoch: 700 | Iteration:  42 x 5000 | Score: 0.999983333333 | Loss:  0.0003889926 | Time elapsed: 97.96 minutes
Epoch: 716 | Iteration:  43 x 5000 | Score: 0.999983333333 | Loss:  0.0003643383 | Time elapsed: 100.26 minutes
Epoch: 733 | Iteration:  44 x 5000 | Score: 1.000000000000 | Loss:  0.0003036954 | Time elapsed: 102.57 minutes
Epoch: 750 | Iteration:  45 x 5000 | Score: 1.000000000000 | Loss:  0.0003231927 | Time elapsed: 104.88 minutes
Epoch: 766 | Iteration:  46 x 5000 | Score: 1.000000000000 | Loss:  0.0002711087 | Time elapsed: 107.18 minutes
Epoch: 783 | Iteration:  47 x 5000 | Score: 1.000000000000 | Loss:  0.0002542958 | Time elapsed: 109.49 minutes
Epoch: 800 | Iteration:  48 x 5000 | Score: 1.000000000000 | Loss:  0.0002365614 | Time elapsed: 111.81 minutes
Epoch: 816 | Iteration:  49 x 5000 | Score: 1.000000000000 | Loss:  0.0002318410 | Time elapsed: 114.12 minutes
Epoch: 833 | Iteration:  50 x 5000 | Score: 1.000000000000 | Loss:  0.0002087080 | Time elapsed: 116.44 minutes
Epoch: 850 | Iteration:  51 x 5000 | Score: 1.000000000000 | Loss:  0.0001941292 | Time elapsed: 118.76 minutes
Epoch: 866 | Iteration:  52 x 5000 | Score: 1.000000000000 | Loss:  0.0001808406 | Time elapsed: 121.06 minutes
Epoch: 883 | Iteration:  53 x 5000 | Score: 1.000000000000 | Loss:  0.0001599686 | Time elapsed: 123.37 minutes
Epoch: 900 | Iteration:  54 x 5000 | Score: 1.000000000000 | Loss:  0.0001653127 | Time elapsed: 125.68 minutes
Epoch: 916 | Iteration:  55 x 5000 | Score: 1.000000000000 | Loss:  0.0001625101 | Time elapsed: 127.98 minutes
Epoch: 933 | Iteration:  56 x 5000 | Score: 1.000000000000 | Loss:  0.0001479592 | Time elapsed: 130.30 minutes
Epoch: 950 | Iteration:  57 x 5000 | Score: 1.000000000000 | Loss:  0.0001314587 | Time elapsed: 132.61 minutes
Epoch: 966 | Iteration:  58 x 5000 | Score: 1.000000000000 | Loss:  0.0001266607 | Time elapsed: 134.91 minutes
Epoch: 983 | Iteration:  59 x 5000 | Score: 1.000000000000 | Loss:  0.0001180674 | Time elapsed: 137.23 minutes
Epoch: 1000 | Iteration:  60 x 5000 | Score: 1.000000000000 | Loss:  0.0001188808 | Time elapsed: 139.54 minutes
Epoch: 1016 | Iteration:  61 x 5000 | Score: 1.000000000000 | Loss:  0.0001089981 | Time elapsed: 141.84 minutes
Epoch: 1033 | Iteration:  62 x 5000 | Score: 1.000000000000 | Loss:  0.0000990910 | Time elapsed: 144.15 minutes
Epoch: 1050 | Iteration:  63 x 5000 | Score: 1.000000000000 | Loss:  0.0000884828 | Time elapsed: 146.49 minutes
Epoch: 1066 | Iteration:  64 x 5000 | Score: 1.000000000000 | Loss:  0.0000874069 | Time elapsed: 148.85 minutes
Epoch: 1083 | Iteration:  65 x 5000 | Score: 1.000000000000 | Loss:  0.0000865396 | Time elapsed: 151.21 minutes
Epoch: 1100 | Iteration:  66 x 5000 | Score: 1.000000000000 | Loss:  0.0000813124 | Time elapsed: 153.57 minutes
Epoch: 1116 | Iteration:  67 x 5000 | Score: 1.000000000000 | Loss:  0.0000743359 | Time elapsed: 155.91 minutes
Epoch: 1133 | Iteration:  68 x 5000 | Score: 1.000000000000 | Loss:  0.0000702689 | Time elapsed: 158.27 minutes
Epoch: 1150 | Iteration:  69 x 5000 | Score: 1.000000000000 | Loss:  0.0000711239 | Time elapsed: 160.63 minutes
Epoch: 1166 | Iteration:  70 x 5000 | Score: 1.000000000000 | Loss:  0.0000585312 | Time elapsed: 162.98 minutes
Epoch: 1183 | Iteration:  71 x 5000 | Score: 1.000000000000 | Loss:  0.0000566331 | Time elapsed: 165.34 minutes
Epoch: 1200 | Iteration:  72 x 5000 | Score: 1.000000000000 | Loss:  0.0000552729 | Time elapsed: 167.68 minutes
Epoch: 1216 | Iteration:  73 x 5000 | Score: 1.000000000000 | Loss:  0.0000572336 | Time elapsed: 169.99 minutes
Epoch: 1233 | Iteration:  74 x 5000 | Score: 1.000000000000 | Loss:  0.0000578400 | Time elapsed: 172.30 minutes
Epoch: 1250 | Iteration:  75 x 5000 | Score: 1.000000000000 | Loss:  0.0000462393 | Time elapsed: 174.61 minutes
Epoch: 1266 | Iteration:  76 x 5000 | Score: 1.000000000000 | Loss:  0.0000478442 | Time elapsed: 176.92 minutes
Epoch: 1283 | Iteration:  77 x 5000 | Score: 1.000000000000 | Loss:  0.0000397843 | Time elapsed: 179.22 minutes
Epoch: 1300 | Iteration:  78 x 5000 | Score: 1.000000000000 | Loss:  0.0000416923 | Time elapsed: 181.53 minutes
Epoch: 1316 | Iteration:  79 x 5000 | Score: 1.000000000000 | Loss:  0.0000412319 | Time elapsed: 183.83 minutes
Epoch: 1333 | Iteration:  80 x 5000 | Score: 1.000000000000 | Loss:  0.0000368051 | Time elapsed: 186.14 minutes
Epoch: 1350 | Iteration:  81 x 5000 | Score: 1.000000000000 | Loss:  0.0000313277 | Time elapsed: 188.46 minutes
Epoch: 1366 | Iteration:  82 x 5000 | Score: 1.000000000000 | Loss:  0.0000440092 | Time elapsed: 190.76 minutes
Epoch: 1383 | Iteration:  83 x 5000 | Score: 1.000000000000 | Loss:  0.0000307707 | Time elapsed: 193.08 minutes
Epoch: 1400 | Iteration:  84 x 5000 | Score: 1.000000000000 | Loss:  0.0000314073 | Time elapsed: 195.40 minutes
Epoch: 1416 | Iteration:  85 x 5000 | Score: 1.000000000000 | Loss:  0.0000326199 | Time elapsed: 197.79 minutes
Epoch: 1433 | Iteration:  86 x 5000 | Score: 1.000000000000 | Loss:  0.0000385108 | Time elapsed: 200.17 minutes
Epoch: 1450 | Iteration:  87 x 5000 | Score: 1.000000000000 | Loss:  0.0000318513 | Time elapsed: 202.53 minutes
Epoch: 1466 | Iteration:  88 x 5000 | Score: 1.000000000000 | Loss:  0.0000282558 | Time elapsed: 204.93 minutes
Epoch: 1483 | Iteration:  89 x 5000 | Score: 1.000000000000 | Loss:  0.0000242431 | Time elapsed: 207.30 minutes
Epoch: 1500 | Iteration:  90 x 5000 | Score: 1.000000000000 | Loss:  0.0000273362 | Time elapsed: 209.65 minutes
Epoch: 1516 | Iteration:  91 x 5000 | Score: 1.000000000000 | Loss:  0.0000236224 | Time elapsed: 212.00 minutes
Epoch: 1533 | Iteration:  92 x 5000 | Score: 1.000000000000 | Loss:  0.0000226805 | Time elapsed: 214.36 minutes
Epoch: 1550 | Iteration:  93 x 5000 | Score: 1.000000000000 | Loss:  0.0000233745 | Time elapsed: 216.72 minutes
Epoch: 1566 | Iteration:  94 x 5000 | Score: 1.000000000000 | Loss:  0.0000221280 | Time elapsed: 219.07 minutes
Epoch: 1583 | Iteration:  95 x 5000 | Score: 1.000000000000 | Loss:  0.0000238414 | Time elapsed: 221.43 minutes
Epoch: 1600 | Iteration:  96 x 5000 | Score: 1.000000000000 | Loss:  0.0000218838 | Time elapsed: 223.79 minutes
Epoch: 1616 | Iteration:  97 x 5000 | Score: 1.000000000000 | Loss:  0.0000252630 | Time elapsed: 226.14 minutes
Epoch: 1633 | Iteration:  98 x 5000 | Score: 1.000000000000 | Loss:  0.0000208027 | Time elapsed: 228.50 minutes
Epoch: 1650 | Iteration:  99 x 5000 | Score: 1.000000000000 | Loss:  0.0000173657 | Time elapsed: 230.86 minutes
Epoch: 1666 | Iteration: 100 x 5000 | Score: 1.000000000000 | Loss:  0.0000172737 | Time elapsed: 233.21 minutes
Epoch: 1683 | Iteration: 101 x 5000 | Score: 1.000000000000 | Loss:  0.0000185854 | Time elapsed: 235.57 minutes
Epoch: 1700 | Iteration: 102 x 5000 | Score: 1.000000000000 | Loss:  0.0000142220 | Time elapsed: 237.93 minutes
Epoch: 1716 | Iteration: 103 x 5000 | Score: 1.000000000000 | Loss:  0.0000162240 | Time elapsed: 240.28 minutes
Epoch: 1733 | Iteration: 104 x 5000 | Score: 1.000000000000 | Loss:  0.0000156838 | Time elapsed: 242.64 minutes
Epoch: 1750 | Iteration: 105 x 5000 | Score: 1.000000000000 | Loss:  0.0000146539 | Time elapsed: 244.99 minutes
Epoch: 1766 | Iteration: 106 x 5000 | Score: 1.000000000000 | Loss:  0.0000157494 | Time elapsed: 247.34 minutes
Epoch: 1783 | Iteration: 107 x 5000 | Score: 1.000000000000 | Loss:  0.0000189354 | Time elapsed: 249.70 minutes
Epoch: 1800 | Iteration: 108 x 5000 | Score: 1.000000000000 | Loss:  0.0000165950 | Time elapsed: 252.05 minutes
Epoch: 1816 | Iteration: 109 x 5000 | Score: 1.000000000000 | Loss:  0.0000149714 | Time elapsed: 254.40 minutes
Epoch: 1833 | Iteration: 110 x 5000 | Score: 1.000000000000 | Loss:  0.0000133486 | Time elapsed: 256.76 minutes
Epoch: 1850 | Iteration: 111 x 5000 | Score: 1.000000000000 | Loss:  0.0000141976 | Time elapsed: 259.12 minutes
Epoch: 1866 | Iteration: 112 x 5000 | Score: 1.000000000000 | Loss:  0.0000141712 | Time elapsed: 261.55 minutes
Epoch: 1883 | Iteration: 113 x 5000 | Score: 1.000000000000 | Loss:  0.0000137027 | Time elapsed: 263.91 minutes
Epoch: 1900 | Iteration: 114 x 5000 | Score: 1.000000000000 | Loss:  0.0000135462 | Time elapsed: 266.27 minutes
Epoch: 1916 | Iteration: 115 x 5000 | Score: 1.000000000000 | Loss:  0.0000128227 | Time elapsed: 268.62 minutes
Epoch: 1933 | Iteration: 116 x 5000 | Score: 1.000000000000 | Loss:  0.0000104275 | Time elapsed: 270.98 minutes
Epoch: 1950 | Iteration: 117 x 5000 | Score: 1.000000000000 | Loss:  0.0000106652 | Time elapsed: 273.34 minutes
Epoch: 1966 | Iteration: 118 x 5000 | Score: 1.000000000000 | Loss:  0.0000113769 | Time elapsed: 275.68 minutes
Epoch: 1983 | Iteration: 119 x 5000 | Score: 1.000000000000 | Loss:  0.0000110719 | Time elapsed: 278.05 minutes
Epoch: 2000 | Iteration: 120 x 5000 | Score: 1.000000000000 | Loss:  0.0000121209 | Time elapsed: 280.41 minutes
Epoch: 2016 | Iteration: 121 x 5000 | Score: 1.000000000000 | Loss:  0.0000110706 | Time elapsed: 282.74 minutes
Epoch: 2033 | Iteration: 122 x 5000 | Score: 1.000000000000 | Loss:  0.0000095897 | Time elapsed: 285.05 minutes
Epoch: 2050 | Iteration: 123 x 5000 | Score: 1.000000000000 | Loss:  0.0000080341 | Time elapsed: 287.39 minutes
Epoch: 2066 | Iteration: 124 x 5000 | Score: 1.000000000000 | Loss:  0.0000092203 | Time elapsed: 289.73 minutes
Epoch: 2083 | Iteration: 125 x 5000 | Score: 1.000000000000 | Loss:  0.0000089755 | Time elapsed: 292.09 minutes
Epoch: 2100 | Iteration: 126 x 5000 | Score: 1.000000000000 | Loss:  0.0000084931 | Time elapsed: 294.45 minutes
Epoch: 2116 | Iteration: 127 x 5000 | Score: 1.000000000000 | Loss:  0.0000082659 | Time elapsed: 296.80 minutes
Epoch: 2133 | Iteration: 128 x 5000 | Score: 1.000000000000 | Loss:  0.0000079714 | Time elapsed: 299.16 minutes
Epoch: 2150 | Iteration: 129 x 5000 | Score: 1.000000000000 | Loss:  0.0000079022 | Time elapsed: 301.52 minutes
Epoch: 2166 | Iteration: 130 x 5000 | Score: 1.000000000000 | Loss:  0.0000075111 | Time elapsed: 303.87 minutes
Epoch: 2183 | Iteration: 131 x 5000 | Score: 1.000000000000 | Loss:  0.0000076016 | Time elapsed: 306.23 minutes
Epoch: 2200 | Iteration: 132 x 5000 | Score: 1.000000000000 | Loss:  0.0000074645 | Time elapsed: 308.54 minutes
Epoch: 2216 | Iteration: 133 x 5000 | Score: 1.000000000000 | Loss:  0.0000072987 | Time elapsed: 310.85 minutes
Epoch: 2233 | Iteration: 134 x 5000 | Score: 1.000000000000 | Loss:  0.0000070764 | Time elapsed: 313.16 minutes
Epoch: 2250 | Iteration: 135 x 5000 | Score: 1.000000000000 | Loss:  0.0000069752 | Time elapsed: 315.52 minutes
Epoch: 2266 | Iteration: 136 x 5000 | Score: 1.000000000000 | Loss:  0.0000068667 | Time elapsed: 317.87 minutes
Epoch: 2283 | Iteration: 137 x 5000 | Score: 1.000000000000 | Loss:  0.0000068594 | Time elapsed: 320.23 minutes
Epoch: 2300 | Iteration: 138 x 5000 | Score: 1.000000000000 | Loss:  0.0000065955 | Time elapsed: 322.59 minutes
Epoch: 2316 | Iteration: 139 x 5000 | Score: 1.000000000000 | Loss:  0.0000067840 | Time elapsed: 324.94 minutes
Epoch: 2333 | Iteration: 140 x 5000 | Score: 1.000000000000 | Loss:  0.0000069965 | Time elapsed: 327.30 minutes
Epoch: 2350 | Iteration: 141 x 5000 | Score: 1.000000000000 | Loss:  0.0000066637 | Time elapsed: 329.66 minutes
Epoch: 2366 | Iteration: 142 x 5000 | Score: 1.000000000000 | Loss:  0.0000064331 | Time elapsed: 332.01 minutes
Epoch: 2383 | Iteration: 143 x 5000 | Score: 1.000000000000 | Loss:  0.0000068948 | Time elapsed: 334.44 minutes
Epoch: 2400 | Iteration: 144 x 5000 | Score: 1.000000000000 | Loss:  0.0000069163 | Time elapsed: 336.87 minutes
Epoch: 2416 | Iteration: 145 x 5000 | Score: 1.000000000000 | Loss:  0.0000063583 | Time elapsed: 339.30 minutes
Epoch: 2433 | Iteration: 146 x 5000 | Score: 1.000000000000 | Loss:  0.0000065578 | Time elapsed: 341.62 minutes
Epoch: 2450 | Iteration: 147 x 5000 | Score: 1.000000000000 | Loss:  0.0000065294 | Time elapsed: 343.95 minutes
Epoch: 2466 | Iteration: 148 x 5000 | Score: 1.000000000000 | Loss:  0.0000063485 | Time elapsed: 346.26 minutes
Epoch: 2483 | Iteration: 149 x 5000 | Score: 1.000000000000 | Loss:  0.0000061236 | Time elapsed: 348.59 minutes
Epoch: 2500 | Iteration: 150 x 5000 | Score: 1.000000000000 | Loss:  0.0000064669 | Time elapsed: 350.91 minutes
Epoch: 2516 | Iteration: 151 x 5000 | Score: 1.000000000000 | Loss:  0.0000062291 | Time elapsed: 353.22 minutes
Epoch: 2533 | Iteration: 152 x 5000 | Score: 1.000000000000 | Loss:  0.0000061162 | Time elapsed: 355.54 minutes
Epoch: 2550 | Iteration: 153 x 5000 | Score: 1.000000000000 | Loss:  0.0000061057 | Time elapsed: 357.86 minutes
Epoch: 2566 | Iteration: 154 x 5000 | Score: 1.000000000000 | Loss:  0.0000062256 | Time elapsed: 360.17 minutes
Epoch: 2583 | Iteration: 155 x 5000 | Score: 1.000000000000 | Loss:  0.0000061936 | Time elapsed: 362.48 minutes
Epoch: 2600 | Iteration: 156 x 5000 | Score: 1.000000000000 | Loss:  0.0000064549 | Time elapsed: 364.80 minutes
Epoch: 2616 | Iteration: 157 x 5000 | Score: 1.000000000000 | Loss:  0.0000061901 | Time elapsed: 367.09 minutes
Epoch: 2633 | Iteration: 158 x 5000 | Score: 1.000000000000 | Loss:  0.0000063566 | Time elapsed: 369.41 minutes
Epoch: 2650 | Iteration: 159 x 5000 | Score: 1.000000000000 | Loss:  0.0000060836 | Time elapsed: 371.73 minutes
Stop at epoch 2650, iteration 795001
average loss of last 6 epochs improved smaller than 1e-08
Latest score : 1.0 | Latest loss  : 6.08358387761e-06
Training takes 371.757359684 minutes.

Plot

In [8]:
%matplotlib inline
import matplotlib.pyplot as plt

import os
fig_directory = '../figures'
if not os.path.exists(fig_directory):
    os.makedirs(fig_directory)

fig_size = (6, 4.5)
fig_dpi = 200
In [22]:
title = 'Training Error Rate Plot of Cross Entropy Error\n'
title += 'Mini-batch: 200; Max-norm: 2\n'
title += 'Layer size: 784, 1024, 1024, 1024\n'
title += 'Momentum: 0.95, 0.95, 0.95, 0.95\n'
title += 'Dropout rate: 0.8, 0.5, 0.5, 0.5\n'
title += 'Dynamic Step Size LR: (1e-2, 1e-1, 4, 1e-5)\n'
title += 'Sigma: sqrt(2/n)\n'
title += 'Training Error rate is {0} at epoch {1}'.format(round(1.0 - losses[0,2],2),
                                                 int(losses[0,0]))

fig = plt.figure(figsize=fig_size)
plt.plot(losses[1:,0], 1.0 - losses[1:,2])
plt.title(title)
plt.xlabel('Number of epochs')
plt.ylabel('Training Error rate')
plt.grid()
plt.show()
fig.savefig('{0}/k5_epoch_vs_error_rate.png'.format(fig_directory),
            dpi=fig_dpi,
            bbox_inches='tight')
In [23]:
title = 'Training Loss of Cross Entropy Error\n'
title += 'Mini-batch: 200; Max-norm: 2\n'
title += 'Layer size: 784, 1024, 1024, 1024\n'
title += 'Momentum: 0.95, 0.95, 0.95, 0.95\n'
title += 'Dropout rate: 0.8, 0.5, 0.5, 0.5\n'
title += 'Dynamic Step Size LR: (1e-2, 1e-1, 4, 1e-5)\n'
title += 'Sigma: sqrt(2/n)\n'
title += 'Training Loss is {0} at epoch {1}'.format(round(losses[0,3],2),
                                           int(losses[0,0]))

fig = plt.figure(figsize=fig_size)
plt.plot(losses[1:,0], losses[1:,3])
plt.title(title)
plt.xlabel('Number of epochs')
plt.ylabel('Training Loss')
plt.grid()
plt.show()
fig.savefig('{0}/k5_epoch_vs_loss.png'.format(fig_directory),
            dpi=fig_dpi,
            bbox_inches='tight')
In [24]:
title = 'Training Error Rate Plot of Cross Entropy Error\n'
title += 'Mini-batch: 200; Max-norm: 2\n'
title += 'Layer size: 784, 1024, 1024, 1024\n'
title += 'Momentum: 0.95, 0.95, 0.95, 0.95\n'
title += 'Dropout rate: 0.8, 0.5, 0.5, 0.5\n'
title += 'Dynamic Step Size LR: (1e-2, 1e-1, 4, 1e-5)\n'
title += 'Sigma: sqrt(2/n)\n'
title += 'Training Error rate is {0} at {1} seconds'.format(round(1.0 - losses[0,2],2),
                                                   round(losses[0,4],2))

fig = plt.figure(figsize=fig_size)
plt.plot(losses[1:,4], 1.0 - losses[1:,2])
plt.title(title)
plt.xlabel('Training time (seconds)')
plt.ylabel('Training Error rate')
plt.grid()
plt.show()
fig.savefig('{0}/k5_time_vs_error_rate.png'.format(fig_directory),
            dpi=fig_dpi,
            bbox_inches='tight')
In [25]:
title = 'Training Loss of Cross Entropy Error\n'
title += 'Mini-batch: 200; Max-norm: 2\n'
title += 'Layer size: 784, 1024, 1024, 1024\n'
title += 'Momentum: 0.95, 0.95, 0.95, 0.95\n'
title += 'Dropout rate: 0.8, 0.5, 0.5, 0.5\n'
title += 'Dynamic Step Size LR: (1e-2, 1e-1, 4, 1e-5)\n'
title += 'Sigma: sqrt(2/n)\n'
title += 'Training Loss is {0} at {1} seconds'.format(round(losses[0,3],2),
                                             round(losses[0,4],2))

fig = plt.figure(figsize=fig_size)
plt.plot(losses[1:,4], losses[1:,3])
plt.title(title)
plt.xlabel('Training time (seconds)')
plt.ylabel('Training Loss')
plt.grid()
plt.show()
fig.savefig('{0}/k5_time_vs_loss.png'.format(fig_directory),
            dpi=fig_dpi,
            bbox_inches='tight')

Predictions

In [13]:
test_data_path = "../digit-dataset/test.mat"
test_data = io.loadmat(test_data_path)
test_data_size = len(test_data['test_images'][0][0])
test_images = reg.transform(np.array([test_data['test_images'][:,:,i].flatten() for i in xrange(test_data_size)]))
In [14]:
predictions = net.predict(test_images)
In [15]:
import csv

kaggle_result_path = './kaggle5_predictions.csv'

with open(kaggle_result_path, 'w') as fp:
    writer = csv.writer(fp, delimiter=',')
    writer.writerow(['Id', 'Category'])
    for i in xrange(len(predictions)):
        writer.writerow([i+1, int(predictions[i])])

Dump

In [26]:
net.dump('kaggle5.dump', reg)

Shutdown cudamat !!!!!!!!!!

In [27]:
cm.cublas_shutdown()
In [ ]: