|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": 11, |
| 5 | + "execution_count": 1, |
6 | 6 | "metadata": {}, |
7 | | - "outputs": [], |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stderr", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "Using TensorFlow backend.\n" |
| 13 | + ] |
| 14 | + } |
| 15 | + ], |
8 | 16 | "source": [ |
9 | 17 | "import pandas as pd\n", |
10 | 18 | "import numpy as np\n", |
|
21 | 29 | }, |
22 | 30 | { |
23 | 31 | "cell_type": "code", |
24 | | - "execution_count": 5, |
| 32 | + "execution_count": 2, |
25 | 33 | "metadata": {}, |
26 | | - "outputs": [ |
27 | | - { |
28 | | - "name": "stdout", |
29 | | - "output_type": "stream", |
30 | | - "text": [ |
31 | | - "Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz\n", |
32 | | - "170500096/170498071 [==============================] - 263s 2us/step\n" |
33 | | - ] |
34 | | - } |
35 | | - ], |
| 34 | + "outputs": [], |
36 | 35 | "source": [ |
37 | 36 | "(x_train, y_train), (x_test, y_test) = cifar10.load_data()" |
38 | 37 | ] |
39 | 38 | }, |
40 | 39 | { |
41 | 40 | "cell_type": "code", |
42 | | - "execution_count": 6, |
| 41 | + "execution_count": 3, |
43 | 42 | "metadata": {}, |
44 | 43 | "outputs": [ |
45 | 44 | { |
|
48 | 47 | "(50000, 32, 32, 3)" |
49 | 48 | ] |
50 | 49 | }, |
51 | | - "execution_count": 6, |
| 50 | + "execution_count": 3, |
52 | 51 | "metadata": {}, |
53 | 52 | "output_type": "execute_result" |
54 | 53 | } |
|
59 | 58 | }, |
60 | 59 | { |
61 | 60 | "cell_type": "code", |
62 | | - "execution_count": 7, |
| 61 | + "execution_count": 4, |
63 | 62 | "metadata": {}, |
64 | 63 | "outputs": [ |
65 | 64 | { |
|
68 | 67 | "(50000, 1)" |
69 | 68 | ] |
70 | 69 | }, |
71 | | - "execution_count": 7, |
| 70 | + "execution_count": 4, |
72 | 71 | "metadata": {}, |
73 | 72 | "output_type": "execute_result" |
74 | 73 | } |
|
79 | 78 | }, |
80 | 79 | { |
81 | 80 | "cell_type": "code", |
82 | | - "execution_count": 8, |
| 81 | + "execution_count": 5, |
83 | 82 | "metadata": {}, |
84 | 83 | "outputs": [], |
85 | 84 | "source": [ |
|
89 | 88 | }, |
90 | 89 | { |
91 | 90 | "cell_type": "code", |
92 | | - "execution_count": 9, |
| 91 | + "execution_count": 6, |
93 | 92 | "metadata": {}, |
94 | 93 | "outputs": [], |
95 | 94 | "source": [ |
|
99 | 98 | "y_test = label_binarizer.transform(y_test)" |
100 | 99 | ] |
101 | 100 | }, |
| 101 | + { |
| 102 | + "cell_type": "markdown", |
| 103 | + "metadata": {}, |
| 104 | + "source": [ |
| 105 | + "## Model without regularization" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "code", |
| 110 | + "execution_count": 7, |
| 111 | + "metadata": {}, |
| 112 | + "outputs": [ |
| 113 | + { |
| 114 | + "name": "stdout", |
| 115 | + "output_type": "stream", |
| 116 | + "text": [ |
| 117 | + "WARNING:tensorflow:From C:\\Users\\Maedr3\\AppData\\Roaming\\Python\\Python36\\site-packages\\tensorflow\\python\\framework\\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", |
| 118 | + "Instructions for updating:\n", |
| 119 | + "Colocations handled automatically by placer.\n", |
| 120 | + "_________________________________________________________________\n", |
| 121 | + "Layer (type) Output Shape Param # \n", |
| 122 | + "=================================================================\n", |
| 123 | + "conv2d_1 (Conv2D) (None, 32, 32, 32) 896 \n", |
| 124 | + "_________________________________________________________________\n", |
| 125 | + "conv2d_2 (Conv2D) (None, 30, 30, 32) 9248 \n", |
| 126 | + "_________________________________________________________________\n", |
| 127 | + "max_pooling2d_1 (MaxPooling2 (None, 15, 15, 32) 0 \n", |
| 128 | + "_________________________________________________________________\n", |
| 129 | + "flatten_1 (Flatten) (None, 7200) 0 \n", |
| 130 | + "_________________________________________________________________\n", |
| 131 | + "dense_1 (Dense) (None, 512) 3686912 \n", |
| 132 | + "_________________________________________________________________\n", |
| 133 | + "dense_2 (Dense) (None, 10) 5130 \n", |
| 134 | + "=================================================================\n", |
| 135 | + "Total params: 3,702,186\n", |
| 136 | + "Trainable params: 3,702,186\n", |
| 137 | + "Non-trainable params: 0\n", |
| 138 | + "_________________________________________________________________\n" |
| 139 | + ] |
| 140 | + } |
| 141 | + ], |
| 142 | + "source": [ |
| 143 | + "model = Sequential()\n", |
| 144 | + " \n", |
| 145 | + "model.add(Conv2D(32, (3, 3), activation='relu', padding='same', input_shape=(32,32,3))) \n", |
| 146 | + "model.add(Conv2D(32, (3, 3), activation='relu')) \n", |
| 147 | + "model.add(MaxPool2D(pool_size=(2, 2)))\n", |
| 148 | + "\n", |
| 149 | + "model.add(Flatten())\n", |
| 150 | + "\n", |
| 151 | + "model.add(Dense(512, activation='relu'))\n", |
| 152 | + "\n", |
| 153 | + "model.add(Dense(10, activation='softmax'))\n", |
| 154 | + "\n", |
| 155 | + "model.summary()\n", |
| 156 | + "\n", |
| 157 | + "model.compile(loss='categorical_crossentropy', \n", |
| 158 | + " optimizer='adam',\n", |
| 159 | + " metrics = ['accuracy'])" |
| 160 | + ] |
| 161 | + }, |
| 162 | + { |
| 163 | + "cell_type": "code", |
| 164 | + "execution_count": 8, |
| 165 | + "metadata": {}, |
| 166 | + "outputs": [ |
| 167 | + { |
| 168 | + "name": "stdout", |
| 169 | + "output_type": "stream", |
| 170 | + "text": [ |
| 171 | + "WARNING:tensorflow:From C:\\Users\\Maedr3\\AppData\\Roaming\\Python\\Python36\\site-packages\\tensorflow\\python\\ops\\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", |
| 172 | + "Instructions for updating:\n", |
| 173 | + "Use tf.cast instead.\n", |
| 174 | + "Train on 50000 samples, validate on 10000 samples\n", |
| 175 | + "Epoch 1/10\n", |
| 176 | + "50000/50000 [==============================] - 318s 6ms/step - loss: 14.4860 - acc: 0.1003 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 177 | + "Epoch 2/10\n", |
| 178 | + "50000/50000 [==============================] - 329s 7ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 179 | + "Epoch 3/10\n", |
| 180 | + "50000/50000 [==============================] - 344s 7ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 181 | + "Epoch 4/10\n", |
| 182 | + "50000/50000 [==============================] - 320s 6ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 183 | + "Epoch 5/10\n", |
| 184 | + "50000/50000 [==============================] - 304s 6ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 185 | + "Epoch 6/10\n", |
| 186 | + "50000/50000 [==============================] - 306s 6ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 187 | + "Epoch 7/10\n", |
| 188 | + "50000/50000 [==============================] - 312s 6ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 189 | + "Epoch 8/10\n", |
| 190 | + "50000/50000 [==============================] - 317s 6ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 191 | + "Epoch 9/10\n", |
| 192 | + "50000/50000 [==============================] - 311s 6ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n", |
| 193 | + "Epoch 10/10\n", |
| 194 | + "50000/50000 [==============================] - 306s 6ms/step - loss: 14.5063 - acc: 0.1000 - val_loss: 14.5063 - val_acc: 0.1000\n" |
| 195 | + ] |
| 196 | + } |
| 197 | + ], |
| 198 | + "source": [ |
| 199 | + "model_details = model.fit(x_train, y_train,\n", |
| 200 | + " batch_size = 512, \n", |
| 201 | + " epochs = 10, \n", |
| 202 | + " validation_data= (x_test, y_test),\n", |
| 203 | + " verbose=1)" |
| 204 | + ] |
| 205 | + }, |
| 206 | + { |
| 207 | + "cell_type": "code", |
| 208 | + "execution_count": 10, |
| 209 | + "metadata": {}, |
| 210 | + "outputs": [ |
| 211 | + { |
| 212 | + "name": "stdout", |
| 213 | + "output_type": "stream", |
| 214 | + "text": [ |
| 215 | + "10000/10000 [==============================] - 21s 2ms/step\n", |
| 216 | + "Accuracy: 10.00%\n" |
| 217 | + ] |
| 218 | + } |
| 219 | + ], |
| 220 | + "source": [ |
| 221 | + "score = model.evaluate(x_test, y_test)\n", |
| 222 | + "print(\"Accuracy: {0:.2f}%\".format(score[1]*100))" |
| 223 | + ] |
| 224 | + }, |
| 225 | + { |
| 226 | + "cell_type": "markdown", |
| 227 | + "metadata": {}, |
| 228 | + "source": [ |
| 229 | + "## Model with regularization" |
| 230 | + ] |
| 231 | + }, |
102 | 232 | { |
103 | 233 | "cell_type": "code", |
104 | 234 | "execution_count": 19, |
|
272 | 402 | { |
273 | 403 | "cell_type": "code", |
274 | 404 | "execution_count": 33, |
275 | | - "metadata": {}, |
| 405 | + "metadata": { |
| 406 | + "scrolled": true |
| 407 | + }, |
276 | 408 | "outputs": [ |
277 | 409 | { |
278 | 410 | "data": { |
|
332 | 464 | "plt.show()\n", |
333 | 465 | "print(\"Prediction: {0}\".format(labels[np.argmax(y_pred[correct_indices[image]])]))" |
334 | 466 | ] |
335 | | - }, |
336 | | - { |
337 | | - "cell_type": "code", |
338 | | - "execution_count": null, |
339 | | - "metadata": {}, |
340 | | - "outputs": [], |
341 | | - "source": [] |
342 | 467 | } |
343 | 468 | ], |
344 | 469 | "metadata": { |
|
0 commit comments