Created
August 3, 2022 18:49
-
-
Save csgeeek/cc343a9b0bb41e8dcdc4f3641df0be6f to your computer and use it in GitHub Desktop.
tf-prac.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": "tf-prac.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyMmAqCgNoL4uFv6/BOFPNut", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/Yaswanth820/cc343a9b0bb41e8dcdc4f3641df0be6f/tf-prac.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "JCLHseqR8Dk3", | |
"outputId": "961ec4fb-2e36-49f1-bdf1-c9a2b2863290" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"2.8.2\n" | |
] | |
} | |
], | |
"source": [ | |
"import tensorflow as tf\n", | |
"import numpy as np\n", | |
"print(tf.__version__)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"fashion_mnist = tf.keras.datasets.fashion_mnist\n", | |
"(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "2BUtn7Hf82xB", | |
"outputId": "ed65cc77-6bf5-483d-c645-65e48acef856" | |
}, | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz\n", | |
"32768/29515 [=================================] - 0s 0us/step\n", | |
"40960/29515 [=========================================] - 0s 0us/step\n", | |
"Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz\n", | |
"26427392/26421880 [==============================] - 0s 0us/step\n", | |
"26435584/26421880 [==============================] - 0s 0us/step\n", | |
"Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz\n", | |
"16384/5148 [===============================================================================================] - 0s 0us/step\n", | |
"Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz\n", | |
"4423680/4422102 [==============================] - 0s 0us/step\n", | |
"4431872/4422102 [==============================] - 0s 0us/step\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']\n", | |
"x_train.shape" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "LLx8IFxL9IxH", | |
"outputId": "3a0cefc7-632a-4084-b55b-320c597702b9" | |
}, | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"(60000, 28, 28)" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 3 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model = tf.keras.Sequential([\n", | |
" tf.keras.layers.Flatten(input_shape=(28, 28)),\n", | |
" tf.keras.layers.Dense(128, activation='relu'),\n", | |
" tf.keras.layers.Dense(10)\n", | |
"])" | |
], | |
"metadata": { | |
"id": "LYl_cJmE9nff" | |
}, | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model.compile(\n", | |
" optimizer='adam',\n", | |
" loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n", | |
" metrics=['accuracy']\n", | |
")" | |
], | |
"metadata": { | |
"id": "BnsGDGvi-HIV" | |
}, | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model.fit(x_train, y_train, epochs=10)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "5onfochE-owh", | |
"outputId": "950b7f0a-ef17-4ac7-f9f1-0716056d49ea" | |
}, | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Epoch 1/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 3.3322 - accuracy: 0.7030\n", | |
"Epoch 2/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 0.6537 - accuracy: 0.7706\n", | |
"Epoch 3/10\n", | |
"1875/1875 [==============================] - 4s 2ms/step - loss: 0.5677 - accuracy: 0.7989\n", | |
"Epoch 4/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 0.5170 - accuracy: 0.8206\n", | |
"Epoch 5/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 0.4889 - accuracy: 0.8331\n", | |
"Epoch 6/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 0.4769 - accuracy: 0.8378\n", | |
"Epoch 7/10\n", | |
"1875/1875 [==============================] - 4s 2ms/step - loss: 0.4714 - accuracy: 0.8399\n", | |
"Epoch 8/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 0.4599 - accuracy: 0.8425\n", | |
"Epoch 9/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 0.4582 - accuracy: 0.8450\n", | |
"Epoch 10/10\n", | |
"1875/1875 [==============================] - 5s 2ms/step - loss: 0.4464 - accuracy: 0.8470\n" | |
] | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<keras.callbacks.History at 0x7f0195aa1790>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 7 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()])\n", | |
"predictions = probability_model.predict(x_test)\n", | |
"predictions[0]" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "QC_R-Bg9_Hby", | |
"outputId": "82f38fa7-2f2a-4cf8-c531-dff5066cc742" | |
}, | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"array([3.7452521e-14, 1.1022565e-07, 1.3565481e-38, 3.2323789e-11,\n", | |
" 6.0320506e-34, 2.8959396e-03, 2.4874879e-17, 5.2263577e-02,\n", | |
" 2.8615256e-13, 9.4484031e-01], dtype=float32)" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 8 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🚀