{"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 matplotlib.pyplot as plt\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-20T22:00:59.001971Z","iopub.execute_input":"2022-07-20T22:00:59.002992Z","iopub.status.idle":"2022-07-20T22:01:03.933337Z","shell.execute_reply.started":"2022-07-20T22:00:59.00289Z","shell.execute_reply":"2022-07-20T22:01:03.932426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mnist = tf.keras.datasets.mnist\n\n(X_train, y_train), (X_test, y_test) = mnist.load_data()\n\nX_train = tf.keras.utils.normalize(X_train, axis=1)\nX_test = tf.keras.utils.normalize(X_test, axis=1)\n\nmodel = tf.keras.models.Sequential()\nmodel.add(tf.keras.layers.Flatten())\nmodel.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))\nmodel.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))\nmodel.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))\n\nmodel.compile(optimizer='adam', \n             loss='sparse_categorical_crossentropy',\n             metrics=['accuracy'])\n\nmodel.fit(X_train, y_train, epochs=100)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T22:01:03.935191Z","iopub.execute_input":"2022-07-20T22:01:03.935831Z","iopub.status.idle":"2022-07-20T22:07:31.574622Z","shell.execute_reply.started":"2022-07-20T22:01:03.935792Z","shell.execute_reply":"2022-07-20T22:07:31.573515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_loss, val_acc = model.evaluate(X_test, y_test)\nprint(val_loss, val_acc)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T22:07:31.576407Z","iopub.execute_input":"2022-07-20T22:07:31.576995Z","iopub.status.idle":"2022-07-20T22:07:32.433041Z","shell.execute_reply.started":"2022-07-20T22:07:31.576957Z","shell.execute_reply":"2022-07-20T22:07:32.431815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('numberprediction')\nnewModel = tf.keras.models.load_model('numberprediction')\npredictions = newModel.predict([X_test])\nprint(predictions)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T22:07:32.435674Z","iopub.execute_input":"2022-07-20T22:07:32.436394Z","iopub.status.idle":"2022-07-20T22:07:33.910553Z","shell.execute_reply.started":"2022-07-20T22:07:32.436332Z","shell.execute_reply":"2022-07-20T22:07:33.909561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a=0\nfor x in range(9000):\n    print(np.argmax(predictions[x]))\n    plt.imshow(X_test[x])\n    plt.show()\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T22:07:33.912156Z","iopub.execute_input":"2022-07-20T22:07:33.912544Z","iopub.status.idle":"2022-07-20T22:31:55.756627Z","shell.execute_reply.started":"2022-07-20T22:07:33.912504Z","shell.execute_reply":"2022-07-20T22:31:55.755703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(X_train[0], cmap = plt.cm.binary)\nplt.show()\nprint(X_train[0])","metadata":{"execution":{"iopub.status.busy":"2022-07-20T22:31:55.758088Z","iopub.execute_input":"2022-07-20T22:31:55.758456Z","iopub.status.idle":"2022-07-20T22:31:55.924338Z","shell.execute_reply.started":"2022-07-20T22:31:55.758419Z","shell.execute_reply":"2022-07-20T22:31:55.923389Z"},"trusted":true},"execution_count":null,"outputs":[]}]}