Created
February 19, 2020 13:47
-
-
Save HarshCasper/f0003a4996f1784b8707a15692be5094 to your computer and use it in GitHub Desktop.
MNIST_Tensorflow.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "MNIST_Tensorflow.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyN2JP+1jeXpwq0iBtmY17jC", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/HarshCasper/f0003a4996f1784b8707a15692be5094/mnist_tensorflow.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "uLcFmwDGoaqZ", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 96 | |
}, | |
"outputId": "a165a7b4-5331-468a-cb4e-5f754739df7c" | |
}, | |
"source": [ | |
"import tensorflow as tf\n", | |
"mnist = tf.keras.datasets.mnist\n", | |
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n", | |
"x_train, x_test = x_train / 255.0, x_test / 255.0" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/html": [ | |
"<p style=\"color: red;\">\n", | |
"The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.<br>\n", | |
"We recommend you <a href=\"https://www.tensorflow.org/guide/migrate\" target=\"_blank\">upgrade</a> now \n", | |
"or ensure your notebook will continue to use TensorFlow 1.x via the <code>%tensorflow_version 1.x</code> magic:\n", | |
"<a href=\"https://colab.research.google.com/notebooks/tensorflow_version.ipynb\" target=\"_blank\">more info</a>.</p>\n" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz\n", | |
"11493376/11490434 [==============================] - 0s 0us/step\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Ab3zQcNlogmk", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 87 | |
}, | |
"outputId": "2f63dbc2-85b9-4811-b0b6-f17cbd6089e0" | |
}, | |
"source": [ | |
"model = tf.keras.models.Sequential([\n", | |
" tf.keras.layers.Flatten(input_shape=(28, 28)),\n", | |
" tf.keras.layers.Dense(128, activation='relu'),\n", | |
" tf.keras.layers.Dropout(0.2),\n", | |
" tf.keras.layers.Dense(10, activation='softmax')\n", | |
"])\n", | |
"\n", | |
"model.compile(optimizer='adam',\n", | |
" loss='sparse_categorical_crossentropy',\n", | |
" metrics=['accuracy'])" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.\n", | |
"Instructions for updating:\n", | |
"If using Keras pass *_constraint arguments to layers.\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "plTIfDmUop53", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 403 | |
}, | |
"outputId": "c20f44a2-108d-4429-ddb7-81483f1104b3" | |
}, | |
"source": [ | |
"model.fit(x_train, y_train, epochs=10)\n", | |
"model.evaluate(x_test, y_test)" | |
], | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Train on 60000 samples\n", | |
"Epoch 1/10\n", | |
"60000/60000 [==============================] - 4s 73us/sample - loss: 0.0657 - acc: 0.9788\n", | |
"Epoch 2/10\n", | |
"60000/60000 [==============================] - 4s 71us/sample - loss: 0.0588 - acc: 0.9817\n", | |
"Epoch 3/10\n", | |
"60000/60000 [==============================] - 4s 72us/sample - loss: 0.0535 - acc: 0.9826\n", | |
"Epoch 4/10\n", | |
"60000/60000 [==============================] - 4s 72us/sample - loss: 0.0479 - acc: 0.9842\n", | |
"Epoch 5/10\n", | |
"60000/60000 [==============================] - 4s 72us/sample - loss: 0.0451 - acc: 0.9850\n", | |
"Epoch 6/10\n", | |
"60000/60000 [==============================] - 4s 73us/sample - loss: 0.0387 - acc: 0.9869\n", | |
"Epoch 7/10\n", | |
"60000/60000 [==============================] - 4s 72us/sample - loss: 0.0387 - acc: 0.9871\n", | |
"Epoch 8/10\n", | |
"60000/60000 [==============================] - 4s 73us/sample - loss: 0.0352 - acc: 0.9883\n", | |
"Epoch 9/10\n", | |
"60000/60000 [==============================] - 4s 73us/sample - loss: 0.0342 - acc: 0.9885\n", | |
"Epoch 10/10\n", | |
"60000/60000 [==============================] - 4s 72us/sample - loss: 0.0324 - acc: 0.9892\n", | |
"10000/10000 [==============================] - 0s 30us/sample - loss: 0.0827 - acc: 0.9791\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"[0.08271336156373436, 0.9791]" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 4 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "MpaQMRXLorms", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment