{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport tensorflow as tf\nimport os\n\nfrom tensorflow.keras.utils import load_img, img_to_array\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-05-03T15:36:09.562144Z","iopub.execute_input":"2022-05-03T15:36:09.562420Z","iopub.status.idle":"2022-05-03T15:36:09.569034Z","shell.execute_reply.started":"2022-05-03T15:36:09.562392Z","shell.execute_reply":"2022-05-03T15:36:09.568211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(X_train, y_train), (X_val, y_val) = tf.keras.datasets.mnist.load_data()\n\nIMAGE_SIZE = 28","metadata":{"execution":{"iopub.status.busy":"2022-05-03T15:16:55.487399Z","iopub.execute_input":"2022-05-03T15:16:55.488155Z","iopub.status.idle":"2022-05-03T15:16:55.797792Z","shell.execute_reply.started":"2022-05-03T15:16:55.488118Z","shell.execute_reply":"2022-05-03T15:16:55.796985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.Sequential()\nmodel.add(tf.keras.layers.Input((IMAGE_SIZE, IMAGE_SIZE)))\nmodel.add(tf.keras.layers.Reshape((IMAGE_SIZE, IMAGE_SIZE, 1)))\nmodel.add(tf.keras.layers.Conv2D(16, 3, activation='relu'))\nmodel.add(tf.keras.layers.MaxPool2D(2))\nmodel.add(tf.keras.layers.Conv2D(32, 3, activation='relu'))\nmodel.add(tf.keras.layers.MaxPool2D(2))\nmodel.add(tf.keras.layers.Conv2D(32, 3, activation='relu'))\nmodel.add(tf.keras.layers.MaxPool2D(2))\nmodel.add(tf.keras.layers.Flatten())\nmodel.add(tf.keras.layers.Dense(128, activation='relu'))\nmodel.add(tf.keras.layers.Dense(32, activation='relu'))\nmodel.add(tf.keras.layers.Dense(10, activation='softmax'))\nmodel.summary()\n\nmodel.compile(loss='sparse_categorical_crossentropy', metrics=['acc'], optimizer='adam')","metadata":{"execution":{"iopub.status.busy":"2022-05-03T15:29:40.342764Z","iopub.execute_input":"2022-05-03T15:29:40.343251Z","iopub.status.idle":"2022-05-03T15:29:40.465438Z","shell.execute_reply.started":"2022-05-03T15:29:40.343207Z","shell.execute_reply":"2022-05-03T15:29:40.464741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(X_train/255., y_train, validation_data=(X_val/255., y_val), epochs=10)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T15:29:40.841894Z","iopub.execute_input":"2022-05-03T15:29:40.842192Z","iopub.status.idle":"2022-05-03T15:31:03.727283Z","shell.execute_reply.started":"2022-05-03T15:29:40.842160Z","shell.execute_reply":"2022-05-03T15:31:03.726454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# list all data in history\nprint(history.history.keys())\n# summarize history for accuracy\nplt.plot(history.history['acc'])\nplt.plot(history.history['val_acc'])\nplt.title('model accuracy')\nplt.ylabel('accuracy')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.show()\n# summarize history for loss\nplt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('model loss')\nplt.ylabel('loss')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T15:33:38.408516Z","iopub.execute_input":"2022-05-03T15:33:38.409116Z","iopub.status.idle":"2022-05-03T15:33:38.806140Z","shell.execute_reply.started":"2022-05-03T15:33:38.409076Z","shell.execute_reply":"2022-05-03T15:33:38.805363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}