yasirfaizahmed commited on
Commit
8942b9c
1 Parent(s): 1e3d4ab

working code

Browse files
Files changed (1) hide show
  1. notes/mnist.ipynb +276 -109
notes/mnist.ipynb CHANGED
@@ -6,18 +6,18 @@
6
  "id": "b2d6f096-6123-4dd0-ae4f-c9abf70889c4",
7
  "metadata": {
8
  "execution": {
9
- "iopub.execute_input": "2024-04-04T08:47:31.680497Z",
10
- "iopub.status.busy": "2024-04-04T08:47:31.678982Z",
11
- "iopub.status.idle": "2024-04-04T08:47:52.012034Z",
12
- "shell.execute_reply": "2024-04-04T08:47:52.010508Z",
13
- "shell.execute_reply.started": "2024-04-04T08:47:31.680435Z"
14
  }
15
  },
16
  "outputs": [
17
  {
18
  "data": {
19
  "application/vnd.jupyter.widget-view+json": {
20
- "model_id": "f0c8978e9991468cb37176b7ee5e7f40",
21
  "version_major": 2,
22
  "version_minor": 0
23
  },
@@ -31,7 +31,7 @@
31
  {
32
  "data": {
33
  "application/vnd.jupyter.widget-view+json": {
34
- "model_id": "1821c061525d4be1b088a0b1624ba0f7",
35
  "version_major": 2,
36
  "version_minor": 0
37
  },
@@ -52,7 +52,7 @@
52
  {
53
  "data": {
54
  "application/vnd.jupyter.widget-view+json": {
55
- "model_id": "eb3da6f2299d4012862a28dd3a74565d",
56
  "version_major": 2,
57
  "version_minor": 0
58
  },
@@ -66,7 +66,7 @@
66
  {
67
  "data": {
68
  "application/vnd.jupyter.widget-view+json": {
69
- "model_id": "e53657e2c6ad4c108ad703dae1f87efe",
70
  "version_major": 2,
71
  "version_minor": 0
72
  },
@@ -80,7 +80,7 @@
80
  {
81
  "data": {
82
  "application/vnd.jupyter.widget-view+json": {
83
- "model_id": "2407ea55dc5348619ad666a16a3b97ff",
84
  "version_major": 2,
85
  "version_minor": 0
86
  },
@@ -94,7 +94,7 @@
94
  {
95
  "data": {
96
  "application/vnd.jupyter.widget-view+json": {
97
- "model_id": "04a14bdbb03044979afd7c44ba0f424e",
98
  "version_major": 2,
99
  "version_minor": 0
100
  },
@@ -108,7 +108,7 @@
108
  {
109
  "data": {
110
  "application/vnd.jupyter.widget-view+json": {
111
- "model_id": "976dba4172974f01ae37ad90b1c6cb1d",
112
  "version_major": 2,
113
  "version_minor": 0
114
  },
@@ -122,7 +122,7 @@
122
  {
123
  "data": {
124
  "application/vnd.jupyter.widget-view+json": {
125
- "model_id": "56d60d708f2549a5a0c6acc0e2499884",
126
  "version_major": 2,
127
  "version_minor": 0
128
  },
@@ -136,7 +136,7 @@
136
  {
137
  "data": {
138
  "application/vnd.jupyter.widget-view+json": {
139
- "model_id": "87ba67ec7d834407afd7fcf7a9d6ac13",
140
  "version_major": 2,
141
  "version_minor": 0
142
  },
@@ -150,7 +150,7 @@
150
  {
151
  "data": {
152
  "application/vnd.jupyter.widget-view+json": {
153
- "model_id": "696c5019b4c24f049ce78744c1fecded",
154
  "version_major": 2,
155
  "version_minor": 0
156
  },
@@ -171,7 +171,7 @@
171
  {
172
  "data": {
173
  "application/vnd.jupyter.widget-view+json": {
174
- "model_id": "d5193a728c974100b02fcb82ac236d80",
175
  "version_major": 2,
176
  "version_minor": 0
177
  },
@@ -192,14 +192,14 @@
192
  {
193
  "cell_type": "code",
194
  "execution_count": 2,
195
- "id": "7c5ea43d-6a70-4deb-a90e-1d7758c961a3",
196
  "metadata": {
197
  "execution": {
198
- "iopub.execute_input": "2024-04-04T08:47:52.015528Z",
199
- "iopub.status.busy": "2024-04-04T08:47:52.014998Z",
200
- "iopub.status.idle": "2024-04-04T08:47:56.923333Z",
201
- "shell.execute_reply": "2024-04-04T08:47:56.922341Z",
202
- "shell.execute_reply.started": "2024-04-04T08:47:52.015483Z"
203
  }
204
  },
205
  "outputs": [],
@@ -209,55 +209,28 @@
209
  "import io\n",
210
  "import tensorflow as tf\n",
211
  "\n",
212
- "def convert_image(byte_like_str_image):\n",
213
- " return tf.convert_to_tensor(np.asarray(Image.open(io.BytesIO(byte_like_str_image['bytes']))), dtype = tf.float32)"
214
- ]
215
- },
216
- {
217
- "cell_type": "code",
218
- "execution_count": 3,
219
- "id": "daafde17-8100-4f49-b27e-8aad43b129c6",
220
- "metadata": {
221
- "execution": {
222
- "iopub.execute_input": "2024-04-04T08:47:56.925474Z",
223
- "iopub.status.busy": "2024-04-04T08:47:56.924961Z",
224
- "iopub.status.idle": "2024-04-04T08:48:32.236745Z",
225
- "shell.execute_reply": "2024-04-04T08:48:32.234178Z",
226
- "shell.execute_reply.started": "2024-04-04T08:47:56.925446Z"
227
- }
228
- },
229
- "outputs": [],
230
- "source": [
231
- "from keras.utils import to_categorical\n",
232
- "\n",
233
- "dataset_train = dataset['train'].to_pandas()\n",
234
- "dataset_train['image'] = dataset_train['image'].map(convert_image)\n",
235
  "\n",
236
- "dataset_test = dataset['test'].to_pandas()\n",
237
- "dataset_test['image'] = dataset_test['image'].map(convert_image)\n",
238
  "\n",
239
- "# Convert labels to NumPy arrays\n",
240
- "X_train = np.array(dataset_train['image'].tolist())\n",
241
  "y_train = np.array(dataset_train['label'])\n",
242
- "\n",
243
- "X_test = np.array(dataset_test['image'].tolist())\n",
244
  "y_test = np.array(dataset_test['label'])\n",
245
- "# dataset_train['label'] = dataset_train['label'].astype('float32')\n",
246
- "# dataset_test['label'] = dataset_test['label'].astype('float32')\n",
247
- "\n"
248
  ]
249
  },
250
  {
251
  "cell_type": "code",
252
- "execution_count": 4,
253
  "id": "72022fd2-000d-4d5c-88d5-9afc62c283d5",
254
  "metadata": {
255
  "execution": {
256
- "iopub.execute_input": "2024-04-04T08:48:32.239111Z",
257
- "iopub.status.busy": "2024-04-04T08:48:32.238769Z",
258
- "iopub.status.idle": "2024-04-04T08:48:32.369358Z",
259
- "shell.execute_reply": "2024-04-04T08:48:32.367989Z",
260
- "shell.execute_reply.started": "2024-04-04T08:48:32.239071Z"
261
  }
262
  },
263
  "outputs": [],
@@ -273,15 +246,15 @@
273
  },
274
  {
275
  "cell_type": "code",
276
- "execution_count": 5,
277
  "id": "dd7871ac-cacd-4866-bdda-67651f592262",
278
  "metadata": {
279
  "execution": {
280
- "iopub.execute_input": "2024-04-04T08:48:32.371520Z",
281
- "iopub.status.busy": "2024-04-04T08:48:32.371132Z",
282
- "iopub.status.idle": "2024-04-04T08:48:32.391109Z",
283
- "shell.execute_reply": "2024-04-04T08:48:32.390162Z",
284
- "shell.execute_reply.started": "2024-04-04T08:48:32.371484Z"
285
  }
286
  },
287
  "outputs": [],
@@ -295,15 +268,15 @@
295
  },
296
  {
297
  "cell_type": "code",
298
- "execution_count": 6,
299
  "id": "280e0d9d-d9e8-41d9-b9ad-666e84fc0bfa",
300
  "metadata": {
301
  "execution": {
302
- "iopub.execute_input": "2024-04-04T08:48:32.392690Z",
303
- "iopub.status.busy": "2024-04-04T08:48:32.392405Z",
304
- "iopub.status.idle": "2024-04-04T08:49:02.402966Z",
305
- "shell.execute_reply": "2024-04-04T08:49:02.402204Z",
306
- "shell.execute_reply.started": "2024-04-04T08:48:32.392662Z"
307
  }
308
  },
309
  "outputs": [
@@ -311,52 +284,55 @@
311
  "name": "stdout",
312
  "output_type": "stream",
313
  "text": [
314
- "Epoch 1/5\n",
315
- "1875/1875 [==============================] - 7s 3ms/step - loss: 2.6159 - sparse_categorical_accuracy: 0.8597 - val_loss: 0.5951 - val_sparse_categorical_accuracy: 0.8762\n",
316
- "Epoch 2/5\n",
317
- "1875/1875 [==============================] - 6s 3ms/step - loss: 0.4041 - sparse_categorical_accuracy: 0.9071 - val_loss: 0.4567 - val_sparse_categorical_accuracy: 0.9024\n",
318
- "Epoch 3/5\n",
319
- "1875/1875 [==============================] - 6s 3ms/step - loss: 0.2977 - sparse_categorical_accuracy: 0.9247 - val_loss: 0.3300 - val_sparse_categorical_accuracy: 0.9237\n",
320
- "Epoch 4/5\n",
321
- "1875/1875 [==============================] - 5s 3ms/step - loss: 0.2646 - sparse_categorical_accuracy: 0.9344 - val_loss: 0.2909 - val_sparse_categorical_accuracy: 0.9368\n",
322
- "Epoch 5/5\n",
323
- "1875/1875 [==============================] - 5s 3ms/step - loss: 0.2418 - sparse_categorical_accuracy: 0.9391 - val_loss: 0.2886 - val_sparse_categorical_accuracy: 0.9330\n",
324
- "<class 'pandas.core.frame.DataFrame'>\n",
325
- "RangeIndex: 60000 entries, 0 to 59999\n",
326
- "Data columns (total 2 columns):\n",
327
- " # Column Non-Null Count Dtype \n",
328
- "--- ------ -------------- ----- \n",
329
- " 0 image 60000 non-null object\n",
330
- " 1 label 60000 non-null int64 \n",
331
- "dtypes: int64(1), object(1)\n",
332
- "memory usage: 937.6+ KB\n"
 
333
  ]
 
 
 
 
 
 
 
 
 
 
334
  }
335
  ],
336
  "source": [
337
- "# model.fit(\n",
338
- "# dataset_train['image'], dataset_test['label'],\n",
339
- "# epochs=10,\n",
340
- "# validation_data=(dataset_test['image'], dataset_test['label']),\n",
341
- "# )\n",
342
- "# dataset_train['label'].head(50)\n",
343
- "model.fit(X_train, y_train, epochs=5, validation_data=(X_test, y_test))\n",
344
- "\n",
345
- "dataset_train.info()\n",
346
  "\n"
347
  ]
348
  },
349
  {
350
  "cell_type": "code",
351
- "execution_count": 8,
352
  "id": "c7317f9a-14f4-4908-9895-8bc085900e28",
353
  "metadata": {
354
  "execution": {
355
- "iopub.execute_input": "2024-04-04T08:49:35.659063Z",
356
- "iopub.status.busy": "2024-04-04T08:49:35.658449Z",
357
- "iopub.status.idle": "2024-04-04T08:49:36.588926Z",
358
- "shell.execute_reply": "2024-04-04T08:49:36.588088Z",
359
- "shell.execute_reply.started": "2024-04-04T08:49:35.659019Z"
360
  }
361
  },
362
  "outputs": [
@@ -364,16 +340,16 @@
364
  "name": "stdout",
365
  "output_type": "stream",
366
  "text": [
367
- "313/313 [==============================] - 1s 3ms/step - loss: 0.2886 - sparse_categorical_accuracy: 0.9330\n"
368
  ]
369
  },
370
  {
371
  "data": {
372
  "text/plain": [
373
- "0.9330000281333923"
374
  ]
375
  },
376
- "execution_count": 8,
377
  "metadata": {},
378
  "output_type": "execute_result"
379
  }
@@ -382,6 +358,197 @@
382
  "loss, accuracy = model.evaluate(X_test, y_test)\n",
383
  "accuracy"
384
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  }
386
  ],
387
  "metadata": {
 
6
  "id": "b2d6f096-6123-4dd0-ae4f-c9abf70889c4",
7
  "metadata": {
8
  "execution": {
9
+ "iopub.execute_input": "2024-04-04T11:32:11.084868Z",
10
+ "iopub.status.busy": "2024-04-04T11:32:11.084300Z",
11
+ "iopub.status.idle": "2024-04-04T11:32:37.677559Z",
12
+ "shell.execute_reply": "2024-04-04T11:32:37.674899Z",
13
+ "shell.execute_reply.started": "2024-04-04T11:32:11.084821Z"
14
  }
15
  },
16
  "outputs": [
17
  {
18
  "data": {
19
  "application/vnd.jupyter.widget-view+json": {
20
+ "model_id": "89f99ed2104c400c89a0a4079cc36f94",
21
  "version_major": 2,
22
  "version_minor": 0
23
  },
 
31
  {
32
  "data": {
33
  "application/vnd.jupyter.widget-view+json": {
34
+ "model_id": "b925c2c62913473aa1a8047fb2003609",
35
  "version_major": 2,
36
  "version_minor": 0
37
  },
 
52
  {
53
  "data": {
54
  "application/vnd.jupyter.widget-view+json": {
55
+ "model_id": "62bc67afecc2488d84e6dc0d59fb3f1f",
56
  "version_major": 2,
57
  "version_minor": 0
58
  },
 
66
  {
67
  "data": {
68
  "application/vnd.jupyter.widget-view+json": {
69
+ "model_id": "2a2f6c3e41574694948f051a0fe10c3d",
70
  "version_major": 2,
71
  "version_minor": 0
72
  },
 
80
  {
81
  "data": {
82
  "application/vnd.jupyter.widget-view+json": {
83
+ "model_id": "7e7d94cbfe3147ff80323ebe74b0e960",
84
  "version_major": 2,
85
  "version_minor": 0
86
  },
 
94
  {
95
  "data": {
96
  "application/vnd.jupyter.widget-view+json": {
97
+ "model_id": "67f4f2d45c354e7da9114a7638fd2098",
98
  "version_major": 2,
99
  "version_minor": 0
100
  },
 
108
  {
109
  "data": {
110
  "application/vnd.jupyter.widget-view+json": {
111
+ "model_id": "c3ed5a8fe6c64817933a0cd892152949",
112
  "version_major": 2,
113
  "version_minor": 0
114
  },
 
122
  {
123
  "data": {
124
  "application/vnd.jupyter.widget-view+json": {
125
+ "model_id": "347a6af016c54c5098f4544fe8666d2c",
126
  "version_major": 2,
127
  "version_minor": 0
128
  },
 
136
  {
137
  "data": {
138
  "application/vnd.jupyter.widget-view+json": {
139
+ "model_id": "a5d6a4133e5f4b2f99fb819bb879db0f",
140
  "version_major": 2,
141
  "version_minor": 0
142
  },
 
150
  {
151
  "data": {
152
  "application/vnd.jupyter.widget-view+json": {
153
+ "model_id": "7a4468bfba904b6bad4575a5b73a2be1",
154
  "version_major": 2,
155
  "version_minor": 0
156
  },
 
171
  {
172
  "data": {
173
  "application/vnd.jupyter.widget-view+json": {
174
+ "model_id": "a9065c53e61d4dc7b258f008eb91d136",
175
  "version_major": 2,
176
  "version_minor": 0
177
  },
 
192
  {
193
  "cell_type": "code",
194
  "execution_count": 2,
195
+ "id": "ddf255fe-a5dc-47b7-acf8-9bb1c636679f",
196
  "metadata": {
197
  "execution": {
198
+ "iopub.execute_input": "2024-04-04T11:32:37.680763Z",
199
+ "iopub.status.busy": "2024-04-04T11:32:37.680286Z",
200
+ "iopub.status.idle": "2024-04-04T11:32:53.674997Z",
201
+ "shell.execute_reply": "2024-04-04T11:32:53.673895Z",
202
+ "shell.execute_reply.started": "2024-04-04T11:32:37.680723Z"
203
  }
204
  },
205
  "outputs": [],
 
209
  "import io\n",
210
  "import tensorflow as tf\n",
211
  "\n",
212
+ "dataset_train = dataset['train']\n",
213
+ "dataset_test = dataset['test']\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  "\n",
215
+ "X_train = np.array([np.array(PIL_object) for PIL_object in dataset_train['image']], dtype='float32')\n",
216
+ "X_test = np.array([np.array(PIL_object) for PIL_object in dataset_test['image']], dtype='float32')\n",
217
  "\n",
 
 
218
  "y_train = np.array(dataset_train['label'])\n",
 
 
219
  "y_test = np.array(dataset_test['label'])\n",
220
+ " \n"
 
 
221
  ]
222
  },
223
  {
224
  "cell_type": "code",
225
+ "execution_count": 3,
226
  "id": "72022fd2-000d-4d5c-88d5-9afc62c283d5",
227
  "metadata": {
228
  "execution": {
229
+ "iopub.execute_input": "2024-04-04T11:32:53.682038Z",
230
+ "iopub.status.busy": "2024-04-04T11:32:53.681712Z",
231
+ "iopub.status.idle": "2024-04-04T11:32:55.198308Z",
232
+ "shell.execute_reply": "2024-04-04T11:32:55.196384Z",
233
+ "shell.execute_reply.started": "2024-04-04T11:32:53.682010Z"
234
  }
235
  },
236
  "outputs": [],
 
246
  },
247
  {
248
  "cell_type": "code",
249
+ "execution_count": 4,
250
  "id": "dd7871ac-cacd-4866-bdda-67651f592262",
251
  "metadata": {
252
  "execution": {
253
+ "iopub.execute_input": "2024-04-04T11:32:55.224011Z",
254
+ "iopub.status.busy": "2024-04-04T11:32:55.223548Z",
255
+ "iopub.status.idle": "2024-04-04T11:32:55.254034Z",
256
+ "shell.execute_reply": "2024-04-04T11:32:55.252607Z",
257
+ "shell.execute_reply.started": "2024-04-04T11:32:55.223968Z"
258
  }
259
  },
260
  "outputs": [],
 
268
  },
269
  {
270
  "cell_type": "code",
271
+ "execution_count": 5,
272
  "id": "280e0d9d-d9e8-41d9-b9ad-666e84fc0bfa",
273
  "metadata": {
274
  "execution": {
275
+ "iopub.execute_input": "2024-04-04T11:32:55.260216Z",
276
+ "iopub.status.busy": "2024-04-04T11:32:55.259580Z",
277
+ "iopub.status.idle": "2024-04-04T11:34:50.315214Z",
278
+ "shell.execute_reply": "2024-04-04T11:34:50.310372Z",
279
+ "shell.execute_reply.started": "2024-04-04T11:32:55.260155Z"
280
  }
281
  },
282
  "outputs": [
 
284
  "name": "stdout",
285
  "output_type": "stream",
286
  "text": [
287
+ "Epoch 1/10\n",
288
+ "1875/1875 [==============================] - 14s 6ms/step - loss: 2.5253 - sparse_categorical_accuracy: 0.8622 - val_loss: 0.4438 - val_sparse_categorical_accuracy: 0.8893\n",
289
+ "Epoch 2/10\n",
290
+ "1875/1875 [==============================] - 11s 6ms/step - loss: 0.3722 - sparse_categorical_accuracy: 0.9146 - val_loss: 0.3441 - val_sparse_categorical_accuracy: 0.9107\n",
291
+ "Epoch 3/10\n",
292
+ "1875/1875 [==============================] - 10s 5ms/step - loss: 0.2708 - sparse_categorical_accuracy: 0.9325 - val_loss: 0.2953 - val_sparse_categorical_accuracy: 0.9309\n",
293
+ "Epoch 4/10\n",
294
+ "1875/1875 [==============================] - 10s 6ms/step - loss: 0.2511 - sparse_categorical_accuracy: 0.9359 - val_loss: 0.2580 - val_sparse_categorical_accuracy: 0.9378\n",
295
+ "Epoch 5/10\n",
296
+ "1875/1875 [==============================] - 11s 6ms/step - loss: 0.2224 - sparse_categorical_accuracy: 0.9435 - val_loss: 0.2646 - val_sparse_categorical_accuracy: 0.9400\n",
297
+ "Epoch 6/10\n",
298
+ "1875/1875 [==============================] - 11s 6ms/step - loss: 0.2134 - sparse_categorical_accuracy: 0.9463 - val_loss: 0.2550 - val_sparse_categorical_accuracy: 0.9456\n",
299
+ "Epoch 7/10\n",
300
+ "1875/1875 [==============================] - 11s 6ms/step - loss: 0.1993 - sparse_categorical_accuracy: 0.9509 - val_loss: 0.2359 - val_sparse_categorical_accuracy: 0.9508\n",
301
+ "Epoch 8/10\n",
302
+ "1875/1875 [==============================] - 12s 6ms/step - loss: 0.1871 - sparse_categorical_accuracy: 0.9545 - val_loss: 0.2501 - val_sparse_categorical_accuracy: 0.9499\n",
303
+ "Epoch 9/10\n",
304
+ "1875/1875 [==============================] - 13s 7ms/step - loss: 0.1875 - sparse_categorical_accuracy: 0.9549 - val_loss: 0.2230 - val_sparse_categorical_accuracy: 0.9496\n",
305
+ "Epoch 10/10\n",
306
+ "1875/1875 [==============================] - 11s 6ms/step - loss: 0.1766 - sparse_categorical_accuracy: 0.9570 - val_loss: 0.2856 - val_sparse_categorical_accuracy: 0.9465\n"
307
  ]
308
+ },
309
+ {
310
+ "data": {
311
+ "text/plain": [
312
+ "<keras.callbacks.History at 0x7fd5e51fc5e0>"
313
+ ]
314
+ },
315
+ "execution_count": 5,
316
+ "metadata": {},
317
+ "output_type": "execute_result"
318
  }
319
  ],
320
  "source": [
321
+ "model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test))\n",
 
 
 
 
 
 
 
 
322
  "\n"
323
  ]
324
  },
325
  {
326
  "cell_type": "code",
327
+ "execution_count": 6,
328
  "id": "c7317f9a-14f4-4908-9895-8bc085900e28",
329
  "metadata": {
330
  "execution": {
331
+ "iopub.execute_input": "2024-04-04T11:34:50.323252Z",
332
+ "iopub.status.busy": "2024-04-04T11:34:50.322859Z",
333
+ "iopub.status.idle": "2024-04-04T11:34:51.995390Z",
334
+ "shell.execute_reply": "2024-04-04T11:34:51.994131Z",
335
+ "shell.execute_reply.started": "2024-04-04T11:34:50.323222Z"
336
  }
337
  },
338
  "outputs": [
 
340
  "name": "stdout",
341
  "output_type": "stream",
342
  "text": [
343
+ "313/313 [==============================] - 2s 5ms/step - loss: 0.2856 - sparse_categorical_accuracy: 0.9465\n"
344
  ]
345
  },
346
  {
347
  "data": {
348
  "text/plain": [
349
+ "0.9465000033378601"
350
  ]
351
  },
352
+ "execution_count": 6,
353
  "metadata": {},
354
  "output_type": "execute_result"
355
  }
 
358
  "loss, accuracy = model.evaluate(X_test, y_test)\n",
359
  "accuracy"
360
  ]
361
+ },
362
+ {
363
+ "cell_type": "code",
364
+ "execution_count": 7,
365
+ "id": "4aaf2641-a8e4-450b-b5c9-230c18211377",
366
+ "metadata": {
367
+ "execution": {
368
+ "iopub.execute_input": "2024-04-04T11:34:52.005924Z",
369
+ "iopub.status.busy": "2024-04-04T11:34:52.004025Z",
370
+ "iopub.status.idle": "2024-04-04T11:34:52.106193Z",
371
+ "shell.execute_reply": "2024-04-04T11:34:52.104405Z",
372
+ "shell.execute_reply.started": "2024-04-04T11:34:52.005782Z"
373
+ }
374
+ },
375
+ "outputs": [],
376
+ "source": [
377
+ "model.save(\"../models/mnist-digit-classification.keras\")"
378
+ ]
379
+ },
380
+ {
381
+ "cell_type": "code",
382
+ "execution_count": 17,
383
+ "id": "3a9debbe-0995-403c-8667-947824f0735e",
384
+ "metadata": {
385
+ "execution": {
386
+ "iopub.execute_input": "2024-04-04T11:40:29.415780Z",
387
+ "iopub.status.busy": "2024-04-04T11:40:29.415049Z",
388
+ "iopub.status.idle": "2024-04-04T11:40:32.417113Z",
389
+ "shell.execute_reply": "2024-04-04T11:40:32.415279Z",
390
+ "shell.execute_reply.started": "2024-04-04T11:40:29.415741Z"
391
+ }
392
+ },
393
+ "outputs": [
394
+ {
395
+ "name": "stdout",
396
+ "output_type": "stream",
397
+ "text": [
398
+ "1/1 [==============================] - 0s 33ms/step\n",
399
+ "[[ -1.8562375 41.656296 46.951298 45.414635 20.483383 27.385012\n",
400
+ " -48.246223 58.661873 26.281921 26.166122 ]]\n",
401
+ "1/1 [==============================] - 0s 38ms/step\n",
402
+ "[[ -1.8562375 41.656296 46.951298 45.414635 20.483383 27.385012\n",
403
+ " -48.246223 58.661873 26.281921 26.166122 ]]\n"
404
+ ]
405
+ },
406
+ {
407
+ "data": {
408
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAAAAABXZoBIAAAAxUlEQVR4nGNgGDaAEUKFpD77sfTFHeyS9xQYGBg+X4UKPuk6w8DAwMDAAuGm6l/TMnSweCzLwPDntSTDozPIOhkYGBgYBA3PmDIw/Lh1XShnGi5nBP+9KIRLTuzl/2AokwlDMlv0/U1cGq1//rPDJcfQ+m83Ky45zrM/rHBqrPu3Daec9+8PlrjkhO/+W4ZLjvn0v9vKuCTV/v3zxSUn/+BfMSMuydZ//0xwydl+QpdEClsbHoa7X1AkWZA5F53f4TIWEwAAaRE8kJuHrgAAAAAASUVORK5CYII=\n",
409
+ "text/plain": [
410
+ "<PIL.PngImagePlugin.PngImageFile image mode=L size=28x28>"
411
+ ]
412
+ },
413
+ "execution_count": 17,
414
+ "metadata": {},
415
+ "output_type": "execute_result"
416
+ }
417
+ ],
418
+ "source": [
419
+ "index = 0\n",
420
+ "IMAGE_HEIGHT = 28\n",
421
+ "IMAGE_WIDTH = 28\n",
422
+ "IMAGE_CHANNEL = 1\n",
423
+ "\n",
424
+ "# image_to_predict = np.reshape(X_test[0], (1, 28, 28, 1))\n",
425
+ "image_to_predict = np.reshape(np.array(dataset_test['image'][index]), (1, IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_CHANNEL))\n",
426
+ "print(model.predict(image_to_predict))\n",
427
+ "\n",
428
+ "\n",
429
+ "image_to_predict = np.reshape(X_test[index], (1, 28, 28, 1))\n",
430
+ "print(model.predict(image_to_predict))\n",
431
+ "\n",
432
+ "dataset_test['image'][index]"
433
+ ]
434
+ },
435
+ {
436
+ "cell_type": "code",
437
+ "execution_count": 11,
438
+ "id": "7e213156-9fe7-422a-bbf1-05ba92584d0a",
439
+ "metadata": {
440
+ "execution": {
441
+ "iopub.execute_input": "2024-04-04T11:36:15.067062Z",
442
+ "iopub.status.busy": "2024-04-04T11:36:15.066433Z",
443
+ "iopub.status.idle": "2024-04-04T11:36:16.695706Z",
444
+ "shell.execute_reply": "2024-04-04T11:36:16.693747Z",
445
+ "shell.execute_reply.started": "2024-04-04T11:36:15.067008Z"
446
+ }
447
+ },
448
+ "outputs": [
449
+ {
450
+ "data": {
451
+ "text/plain": [
452
+ "array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
453
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
454
+ " 0, 0],\n",
455
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
456
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
457
+ " 0, 0],\n",
458
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
459
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
460
+ " 0, 0],\n",
461
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
462
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
463
+ " 0, 0],\n",
464
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
465
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
466
+ " 0, 0],\n",
467
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
468
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
469
+ " 0, 0],\n",
470
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
471
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
472
+ " 0, 0],\n",
473
+ " [ 0, 0, 0, 0, 0, 0, 84, 185, 159, 151, 60, 36, 0,\n",
474
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
475
+ " 0, 0],\n",
476
+ " [ 0, 0, 0, 0, 0, 0, 222, 254, 254, 254, 254, 241, 198,\n",
477
+ " 198, 198, 198, 198, 198, 198, 198, 170, 52, 0, 0, 0, 0,\n",
478
+ " 0, 0],\n",
479
+ " [ 0, 0, 0, 0, 0, 0, 67, 114, 72, 114, 163, 227, 254,\n",
480
+ " 225, 254, 254, 254, 250, 229, 254, 254, 140, 0, 0, 0, 0,\n",
481
+ " 0, 0],\n",
482
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 66,\n",
483
+ " 14, 67, 67, 67, 59, 21, 236, 254, 106, 0, 0, 0, 0,\n",
484
+ " 0, 0],\n",
485
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
486
+ " 0, 0, 0, 0, 0, 83, 253, 209, 18, 0, 0, 0, 0,\n",
487
+ " 0, 0],\n",
488
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
489
+ " 0, 0, 0, 0, 22, 233, 255, 83, 0, 0, 0, 0, 0,\n",
490
+ " 0, 0],\n",
491
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
492
+ " 0, 0, 0, 0, 129, 254, 238, 44, 0, 0, 0, 0, 0,\n",
493
+ " 0, 0],\n",
494
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
495
+ " 0, 0, 0, 59, 249, 254, 62, 0, 0, 0, 0, 0, 0,\n",
496
+ " 0, 0],\n",
497
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
498
+ " 0, 0, 0, 133, 254, 187, 5, 0, 0, 0, 0, 0, 0,\n",
499
+ " 0, 0],\n",
500
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
501
+ " 0, 0, 9, 205, 248, 58, 0, 0, 0, 0, 0, 0, 0,\n",
502
+ " 0, 0],\n",
503
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
504
+ " 0, 0, 126, 254, 182, 0, 0, 0, 0, 0, 0, 0, 0,\n",
505
+ " 0, 0],\n",
506
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
507
+ " 0, 75, 251, 240, 57, 0, 0, 0, 0, 0, 0, 0, 0,\n",
508
+ " 0, 0],\n",
509
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
510
+ " 19, 221, 254, 166, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
511
+ " 0, 0],\n",
512
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,\n",
513
+ " 203, 254, 219, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
514
+ " 0, 0],\n",
515
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38,\n",
516
+ " 254, 254, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
517
+ " 0, 0],\n",
518
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 224,\n",
519
+ " 254, 115, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
520
+ " 0, 0],\n",
521
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 133, 254,\n",
522
+ " 254, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
523
+ " 0, 0],\n",
524
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 242, 254,\n",
525
+ " 254, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
526
+ " 0, 0],\n",
527
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 254, 254,\n",
528
+ " 219, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
529
+ " 0, 0],\n",
530
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 254, 207,\n",
531
+ " 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
532
+ " 0, 0],\n",
533
+ " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
534
+ " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
535
+ " 0, 0]], dtype=uint8)"
536
+ ]
537
+ },
538
+ "execution_count": 11,
539
+ "metadata": {},
540
+ "output_type": "execute_result"
541
+ }
542
+ ],
543
+ "source": []
544
+ },
545
+ {
546
+ "cell_type": "code",
547
+ "execution_count": null,
548
+ "id": "a9acdfed-d868-441f-8123-8002d265b95f",
549
+ "metadata": {},
550
+ "outputs": [],
551
+ "source": []
552
  }
553
  ],
554
  "metadata": {