Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Created using Colaboratory
  • Loading branch information
AmitNaikRepository committed Jun 2, 2020
commit fcb61516b9b5372fe405ff27ae6b10362d58f265
206 changes: 206 additions & 0 deletions keras_simple_tensorboard.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "keras_simple_tensorboard.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyP7jeNbiXxTpmnqHB7+xQdl",
"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/github/AmitNaikRepository/How-to-Deploy-a-Tensorflow-Model-in-Production/blob/master/keras_simple_tensorboard.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "h4ZK-NRymt0U",
"colab_type": "code",
"outputId": "5775d458-4989-4dd6-ce12-335be50ed133",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
}
},
"source": [
"#import liabraries \n",
"import pandas as pd \n",
"import numpy as np \n",
"import tensorflow as tf\n",
"from tensorflow import keras \n",
"from datetime import datetime \n",
"\n",
"from packaging import version \n",
"\n",
"\n",
"print(\"TensorFlow version: \", tf.__version__)\n",
"\n",
"\n",
"assert version.parse(tf.__version__).release[0] >= 2, \\\n",
" \"This notebook requires TensorFlow 2.0 or above.\""
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"TensorFlow version: 2.2.0\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "fjbhPHe4m8C-",
"colab_type": "code",
"colab": {}
},
"source": [
"#import datafile and split the dataset \n",
"data_size=1000\n",
"train_dict=0.8\n",
"\n",
"train_size=int(data_size * train_dict)\n",
"\n",
"x=np.linspace(-1,1,data_size)\n",
"np.random.shuffle(x)\n",
"\n",
"\n",
"\n",
"#generate teh output data \n",
"\n",
"y=0.5*x+2+np.random.normal(0,0.05,(data_size,))\n",
"\n",
"\n",
"#now split the test pair in the data \n",
"\n",
"x_train,y_train=x[:train_size],y[:train_size]\n",
"x_test,y_test=x[train_size:],y[train_size:]"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "lt1NBdTImFoM",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 129
},
"outputId": "6cabb5be-a83a-4e43-9582-68b0c0edad6d"
},
"source": [
"#now import tqdm and intall the process \n",
"logdir=\"logs/scalars/\" + datetime.now().strftime(\"%Y%M%D-%H%M%S\")\n",
"tensorboard_callback=keras.callbacks.TensorBoard(log_dir=logdir)\n",
"\n",
"model=keras.models.Sequential([keras.layers.Dense(16,input_dim=1),\n",
" keras.layers.Dense(1)\n",
" \n",
"])\n",
"\n",
"model.compile(\n",
" loss='mse',\n",
" optimizer=keras.optimizers.SGD(lr=0.2),\n",
")\n",
"\n",
"print(\"training with defualt parameters this takes less than 10 seconds\")\n",
"\n",
"training_history=model.fit(\n",
" x_train,\n",
" y_train,\n",
" batch_size=train_size,\n",
" verbose=0,\n",
" epochs=100,\n",
" validation_data(x_test,y_test),\n",
" callbacks=[tensorboard_callback],\n",
"\n",
"\n",
")\n",
"\n",
"print(\"average test loss \", np.average(training_history.history['loss']))"
],
"execution_count": 7,
"outputs": [
{
"output_type": "error",
"ename": "SyntaxError",
"evalue": "ignored",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-7-9752b521e83b>\"\u001b[0;36m, line \u001b[0;32m23\u001b[0m\n\u001b[0;31m validation_data(x_test,y_test),\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "Yf7YhURUmFlC",
"colab_type": "code",
"colab": {}
},
"source": [
"#get the data and the preprocess it "
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "A2Y_bNS9mFih",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "QacRn8B1mFfB",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "U1wtDvoGmFc6",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}