{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b2d6f096-6123-4dd0-ae4f-c9abf70889c4", "metadata": { "execution": { "iopub.execute_input": "2024-04-04T11:32:11.084868Z", "iopub.status.busy": "2024-04-04T11:32:11.084300Z", "iopub.status.idle": "2024-04-04T11:32:37.677559Z", "shell.execute_reply": "2024-04-04T11:32:37.674899Z", "shell.execute_reply.started": "2024-04-04T11:32:11.084821Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "89f99ed2104c400c89a0a4079cc36f94", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading builder script: 0%| | 0.00/1.63k [00:00" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test))\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "c7317f9a-14f4-4908-9895-8bc085900e28", "metadata": { "execution": { "iopub.execute_input": "2024-04-04T11:34:50.323252Z", "iopub.status.busy": "2024-04-04T11:34:50.322859Z", "iopub.status.idle": "2024-04-04T11:34:51.995390Z", "shell.execute_reply": "2024-04-04T11:34:51.994131Z", "shell.execute_reply.started": "2024-04-04T11:34:50.323222Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "313/313 [==============================] - 2s 5ms/step - loss: 0.2856 - sparse_categorical_accuracy: 0.9465\n" ] }, { "data": { "text/plain": [ "0.9465000033378601" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "loss, accuracy = model.evaluate(X_test, y_test)\n", "accuracy" ] }, { "cell_type": "code", "execution_count": 7, "id": "4aaf2641-a8e4-450b-b5c9-230c18211377", "metadata": { "execution": { "iopub.execute_input": "2024-04-04T11:34:52.005924Z", "iopub.status.busy": "2024-04-04T11:34:52.004025Z", "iopub.status.idle": "2024-04-04T11:34:52.106193Z", "shell.execute_reply": "2024-04-04T11:34:52.104405Z", "shell.execute_reply.started": "2024-04-04T11:34:52.005782Z" } }, "outputs": [], "source": [ "model.save(\"../models/mnist-digit-classification.keras\")" ] }, { "cell_type": "code", "execution_count": 17, "id": "3a9debbe-0995-403c-8667-947824f0735e", "metadata": { "execution": { "iopub.execute_input": "2024-04-04T11:40:29.415780Z", "iopub.status.busy": "2024-04-04T11:40:29.415049Z", "iopub.status.idle": "2024-04-04T11:40:32.417113Z", "shell.execute_reply": "2024-04-04T11:40:32.415279Z", "shell.execute_reply.started": "2024-04-04T11:40:29.415741Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1/1 [==============================] - 0s 33ms/step\n", "[[ -1.8562375 41.656296 46.951298 45.414635 20.483383 27.385012\n", " -48.246223 58.661873 26.281921 26.166122 ]]\n", "1/1 [==============================] - 0s 38ms/step\n", "[[ -1.8562375 41.656296 46.951298 45.414635 20.483383 27.385012\n", " -48.246223 58.661873 26.281921 26.166122 ]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAAAAABXZoBIAAAAxUlEQVR4nGNgGDaAEUKFpD77sfTFHeyS9xQYGBg+X4UKPuk6w8DAwMDAAuGm6l/TMnSweCzLwPDntSTDozPIOhkYGBgYBA3PmDIw/Lh1XShnGi5nBP+9KIRLTuzl/2AokwlDMlv0/U1cGq1//rPDJcfQ+m83Ky45zrM/rHBqrPu3Daec9+8PlrjkhO/+W4ZLjvn0v9vKuCTV/v3zxSUn/+BfMSMuydZ//0xwydl+QpdEClsbHoa7X1AkWZA5F53f4TIWEwAAaRE8kJuHrgAAAAAASUVORK5CYII=\n", "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index = 0\n", "IMAGE_HEIGHT = 28\n", "IMAGE_WIDTH = 28\n", "IMAGE_CHANNEL = 1\n", "\n", "# image_to_predict = np.reshape(X_test[0], (1, 28, 28, 1))\n", "image_to_predict = np.reshape(np.array(dataset_test['image'][index]), (1, IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_CHANNEL))\n", "print(model.predict(image_to_predict))\n", "\n", "\n", "image_to_predict = np.reshape(X_test[index], (1, 28, 28, 1))\n", "print(model.predict(image_to_predict))\n", "\n", "dataset_test['image'][index]" ] }, { "cell_type": "code", "execution_count": 11, "id": "7e213156-9fe7-422a-bbf1-05ba92584d0a", "metadata": { "execution": { "iopub.execute_input": "2024-04-04T11:36:15.067062Z", "iopub.status.busy": "2024-04-04T11:36:15.066433Z", "iopub.status.idle": "2024-04-04T11:36:16.695706Z", "shell.execute_reply": "2024-04-04T11:36:16.693747Z", "shell.execute_reply.started": "2024-04-04T11:36:15.067008Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 84, 185, 159, 151, 60, 36, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 222, 254, 254, 254, 254, 241, 198,\n", " 198, 198, 198, 198, 198, 198, 198, 170, 52, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 67, 114, 72, 114, 163, 227, 254,\n", " 225, 254, 254, 254, 250, 229, 254, 254, 140, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 66,\n", " 14, 67, 67, 67, 59, 21, 236, 254, 106, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 83, 253, 209, 18, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 22, 233, 255, 83, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 129, 254, 238, 44, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 59, 249, 254, 62, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 133, 254, 187, 5, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 9, 205, 248, 58, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 126, 254, 182, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 75, 251, 240, 57, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 19, 221, 254, 166, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,\n", " 203, 254, 219, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38,\n", " 254, 254, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 224,\n", " 254, 115, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 133, 254,\n", " 254, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 242, 254,\n", " 254, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 254, 254,\n", " 219, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 254, 207,\n", " 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0],\n", " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", " 0, 0]], dtype=uint8)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "a9acdfed-d868-441f-8123-8002d265b95f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }