-
-
Save kiransair/ca718d53b64f97f81eb504676568a222 to your computer and use it in GitHub Desktop.
TF_Forum_24144.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": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyPgjhBDdcpaSe9EuPw5lpVn", | |
"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/kiransair/ca718d53b64f97f81eb504676568a222/tf_forum_24144.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": { | |
"id": "uPymGniNGgEC" | |
}, | |
"outputs": [], | |
"source": [ | |
"import tensorflow as tf" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"\n", | |
"inputs = tf.keras.Input(shape=(28, 28, 1))\n", | |
"\n", | |
"conv1 = tf.keras.layers.Conv2D(32, kernel_size=(3, 3), activation='relu')(inputs)\n", | |
"\n", | |
"pool1 = tf.keras.layers.MaxPooling2D(pool_size=(2, 2))(conv1)\n", | |
"\n", | |
"conv2 = tf.keras.layers.Conv2D(64, kernel_size=(3, 3), activation='relu')(pool1)\n", | |
"\n", | |
"x = tf.keras.layers.GlobalAveragePooling2D()(conv2)\n", | |
"\n", | |
"x = tf.keras.layers.Dropout(0.5)(x)\n", | |
"\n", | |
"outputs = tf.keras.layers.Dense(10, activation='softmax')(x)\n", | |
"\n", | |
"model = tf.keras.Model(inputs=inputs, outputs=outputs)" | |
], | |
"metadata": { | |
"id": "ckXeQQp3HAh7" | |
}, | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"converter = tf.lite.TFLiteConverter.from_keras_model(model)" | |
], | |
"metadata": { | |
"id": "6tMHuPatHDKz" | |
}, | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"tflite_model = converter.convert()" | |
], | |
"metadata": { | |
"id": "Xdb_zaZNHIHY" | |
}, | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from tensorflow import keras" | |
], | |
"metadata": { | |
"id": "ZdNqEgdMHNd1" | |
}, | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model1=keras.Sequential([\n", | |
" keras.Input(shape=(28,28,1)),\n", | |
" keras.layers.Conv2D(32,kernel_size=(3,3),activation='relu',),\n", | |
" keras.layers.MaxPooling2D(pool_size=(2,2)),\n", | |
" keras.layers.Conv2D(64,kernel_size=(3,3),activation='relu'),\n", | |
" keras.layers.GlobalAveragePooling2D(),\n", | |
" keras.layers.Dropout(0.5),\n", | |
" keras.layers.Dense(10,activation='softmax')\n", | |
"])" | |
], | |
"metadata": { | |
"id": "zHQyXDilHKRi" | |
}, | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"converter = tf.lite.TFLiteConverter.from_keras_model(model1)" | |
], | |
"metadata": { | |
"id": "Ot5b9RagHRFs" | |
}, | |
"execution_count": 7, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"tflite_model = converter.convert()" | |
], | |
"metadata": { | |
"id": "Sp4xWbAeHUMz" | |
}, | |
"execution_count": 8, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [], | |
"metadata": { | |
"id": "UNcfKaoAHWRx" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment