knuckletouch/python/Step_13_LSTM-Report.ipynb

1053 lines
39 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"source": [
"## USE for Multi GPU Systems\n",
"#import os\n",
"#os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"0\"\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import math\n",
"\n",
"import tensorflow as tf\n",
"\n",
"%matplotlib inline\n",
"\n",
"# Importing SK-learn to calculate precision and recall\n",
"import sklearn\n",
"from sklearn import metrics \n",
"\n",
"# Used for graph export\n",
"from tensorflow.python.framework import graph_util\n",
"from tensorflow.python.framework import graph_io\n",
"from keras import backend as K\n",
"\n",
"\n",
"target_names = [\"tap\", \"twotap\", \"swipeleft\", \"swiperight\", \"swipeup\", \"swipedown\", \"twoswipeup\", \"twoswipedown\", \"circle\", \"arrowheadleft\", \"arrowheadright\", \"checkmark\", \"flashlight\", \"l\", \"lmirrored\", \"screenshot\", \"rotate\"]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 1 2 9 6 4 14 17 16 12 3 10 18 5] [13 8 11 15 7]\n"
]
}
],
"source": [
"df = pd.read_pickle(\"DataStudyCollection/df_lstm_norm50.pkl\")\n",
"\n",
"lst = df.userID.unique()\n",
"np.random.seed(42)\n",
"np.random.shuffle(lst)\n",
"test_ids = lst[-5:]\n",
"train_ids = lst[:-5]\n",
"print(train_ids, test_ids)\n",
"df.TaskID = df.TaskID % 17\n",
"\n",
"x = np.concatenate(df.Blobs.values).reshape(-1,50,27,15,1)\n",
"x = x / 255.0\n",
"\n",
"# convert class vectors to binary class matrices (one-hot notation)\n",
"num_classes = len(df.TaskID.unique())\n",
"y = utils.to_categorical(df.TaskID, num_classes)\n",
"\n",
"labels = sorted(df.TaskID.unique())"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# If GPU is not available: \n",
"# GPU_USE = '/cpu:0'\n",
"#config = tf.ConfigProto(device_count = {\"GPU\": 1})\n",
"\n",
"\n",
"# If GPU is available: \n",
"config = tf.ConfigProto()\n",
"config.log_device_placement = True\n",
"config.allow_soft_placement = True\n",
"config.gpu_options.allow_growth=True\n",
"config.gpu_options.allocator_type = 'BFC'\n",
"\n",
"# Limit the maximum memory used\n",
"config.gpu_options.per_process_gpu_memory_fraction = 0.3\n",
"\n",
"# set session config\n",
"sess = tf.Session(config=config)\n",
"tf.keras.backend.set_session(sess)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"model = tf.keras.models.load_model('./ModelSnapshots/LSTM-v2-00398.h5')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 47.2 s, sys: 6.47 s, total: 53.6 s\n",
"Wall time: 30.9 s\n"
]
}
],
"source": [
"%%time\n",
"lst = []\n",
"batch = 100\n",
"for i in range(0, len(x), batch):\n",
" _x = x[i : i+batch]\n",
" lst.extend(model.predict(_x))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9193"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(df)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"df[\"TaskIDPred\"] = lst\n",
"df.TaskIDPred = df.TaskIDPred.apply(lambda x: np.argmax(x))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"df_train = df[df.userID.isin(train_ids)]\n",
"df_test = df[df.userID.isin(test_ids)]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.9 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. ]]\n",
"Accuray: 0.979\n",
"Recall: 0.979\n",
"F1-Score: 0.978\n",
" precision recall f1-score support\n",
"\n",
" tap 0.94 0.96 0.95 336\n",
" twotap 1.00 1.00 1.00 445\n",
" swipeleft 0.98 0.99 0.98 337\n",
" swiperight 0.95 0.99 0.97 321\n",
" swipeup 0.99 0.99 0.99 325\n",
" swipedown 0.97 0.98 0.97 334\n",
" twoswipeup 1.00 0.99 0.99 434\n",
" twoswipedown 0.99 1.00 0.99 438\n",
" circle 0.99 0.98 0.99 404\n",
" arrowheadleft 0.99 0.96 0.98 388\n",
"arrowheadright 0.98 0.98 0.98 388\n",
" checkmark 0.97 1.00 0.99 364\n",
" flashlight 0.98 0.98 0.98 403\n",
" l 0.99 0.96 0.97 401\n",
" lmirrored 0.94 0.98 0.96 414\n",
" screenshot 0.99 0.94 0.96 402\n",
" rotate 0.97 0.97 0.97 490\n",
"\n",
" micro avg 0.98 0.98 0.98 6624\n",
" macro avg 0.98 0.98 0.98 6624\n",
" weighted avg 0.98 0.98 0.98 6624\n",
"\n"
]
}
],
"source": [
"\n",
"print(sklearn.metrics.confusion_matrix(df_train.TaskID.values, df_train.TaskIDPred.values, labels=labels))\n",
"cm = sklearn.metrics.confusion_matrix(df_train.TaskID.values, df_train.TaskIDPred.values, labels=labels)\n",
"cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
"print(np.round(cm,1))\n",
"print(\"Accuray: %.3f\" % sklearn.metrics.accuracy_score(df_train.TaskID.values, df_train.TaskIDPred.values))\n",
"print(\"Recall: %.3f\" % metrics.recall_score(df_train.TaskID.values, df_train.TaskIDPred.values, average='macro'))\n",
"#print(\"Precision: %.2f\" % metrics.average_precision_score(df_train.TaskID.values, df_train.TaskIDPred.values))\n",
"print(\"F1-Score: %.3f\" % metrics.f1_score(df_train.TaskID.values, df_train.TaskIDPred.values, average='macro'))\n",
"print(sklearn.metrics.classification_report(df_train.TaskID.values, df_train.TaskIDPred.values, target_names=target_names))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 98 5 1 1 0 7 0 5 0 0 0 0 5 0 0 0 4]\n",
" [ 2 130 0 0 4 0 6 1 0 0 0 0 4 0 0 0 1]\n",
" [ 0 0 103 0 0 0 0 0 0 0 0 0 0 0 27 0 0]\n",
" [ 0 0 0 106 0 0 0 0 0 2 0 1 1 17 0 0 0]\n",
" [ 0 0 0 0 116 0 0 0 2 0 0 0 10 0 0 0 0]\n",
" [ 0 0 0 0 1 124 0 0 0 0 0 1 2 0 6 0 1]\n",
" [ 0 0 0 0 17 0 144 0 0 0 0 0 3 0 0 0 0]\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[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.8 0. 0. 0. 0. 0.1 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0.1 0. 0. 0. 0. 0. 0. 0.8 0. 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.9 0. 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.9 0. 0. ]\n",
" [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.9 0. ]\n",
" [0.2 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.8]]\n",
"Accuray: 0.868\n",
"Recall: 0.867\n",
"F1-Score: 0.868\n",
" precision recall f1-score support\n",
"\n",
" tap 0.74 0.78 0.76 126\n",
" twotap 0.94 0.88 0.91 148\n",
" swipeleft 0.96 0.79 0.87 130\n",
" swiperight 0.96 0.83 0.89 127\n",
" swipeup 0.80 0.91 0.85 128\n",
" swipedown 0.73 0.92 0.81 135\n",
" twoswipeup 0.95 0.88 0.91 164\n",
" twoswipedown 0.96 0.89 0.93 169\n",
" circle 0.95 0.78 0.86 166\n",
" arrowheadleft 0.89 0.88 0.89 154\n",
"arrowheadright 0.93 0.82 0.87 152\n",
" checkmark 0.92 0.95 0.93 147\n",
" flashlight 0.82 0.85 0.83 164\n",
" l 0.81 0.94 0.87 159\n",
" lmirrored 0.72 0.93 0.81 163\n",
" screenshot 0.85 0.91 0.88 160\n",
" rotate 0.96 0.80 0.87 177\n",
"\n",
" micro avg 0.87 0.87 0.87 2569\n",
" macro avg 0.88 0.87 0.87 2569\n",
" weighted avg 0.88 0.87 0.87 2569\n",
"\n"
]
}
],
"source": [
"print(sklearn.metrics.confusion_matrix(df_test.TaskID.values, df_test.TaskIDPred.values, labels=labels))\n",
"cm = sklearn.metrics.confusion_matrix(df_test.TaskID.values, df_test.TaskIDPred.values, labels=labels)\n",
"cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
"print(np.round(cm,1))\n",
"print(\"Accuray: %.3f\" % sklearn.metrics.accuracy_score(df_test.TaskID.values, df_test.TaskIDPred.values))\n",
"print(\"Recall: %.3f\" % metrics.recall_score(df_test.TaskID.values, df_test.TaskIDPred.values, average='macro'))\n",
"#print(\"Precision: %.2f\" % metrics.average_precision_score(df_test.TaskID.values, df_test.TaskIDPred.values))\n",
"print(\"F1-Score: %.3f\" % metrics.f1_score(df_test.TaskID.values, df_test.TaskIDPred.values, average='macro'))\n",
"print(sklearn.metrics.classification_report(df_test.TaskID.values, df_test.TaskIDPred.values, target_names=target_names))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Export "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"output nodes names are: ['output_node0']\n"
]
}
],
"source": [
"output_node_prefix = \"output_node\"\n",
"num_output = 1\n",
"pred = [None]*num_output\n",
"pred_node_names = [None]*num_output\n",
"for i in range(num_output):\n",
" pred_node_names[i] = output_node_prefix+str(i)\n",
" pred[i] = tf.identity(model.outputs[i], name=pred_node_names[i])\n",
"print('output nodes names are: ', pred_node_names)\n",
"output_node_prefix = pred_node_names[0]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<tf.Tensor 'time_distributed_10_input:0' shape=(?, 50, 27, 15, 1) dtype=float32>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.inputs[0]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"#sess = K.get_session()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"output_path = \"./Models/\"\n",
"output_file = \"LSTM.pb\""
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"time_distributed_10_input\n",
"time_distributed_10/kernel\n",
"time_distributed_10/kernel/read\n",
"time_distributed_10/bias\n",
"time_distributed_10/bias/read\n",
"time_distributed_10/Reshape/shape\n",
"time_distributed_10/Reshape\n",
"time_distributed_10/convolution\n",
"time_distributed_10/BiasAdd\n",
"time_distributed_10/Relu\n",
"time_distributed_10/Reshape_1/shape\n",
"time_distributed_10/Reshape_1\n",
"time_distributed_11/kernel\n",
"time_distributed_11/kernel/read\n",
"time_distributed_11/bias\n",
"time_distributed_11/bias/read\n",
"time_distributed_11/Reshape/shape\n",
"time_distributed_11/Reshape\n",
"time_distributed_11/convolution\n",
"time_distributed_11/BiasAdd\n",
"time_distributed_11/Relu\n",
"time_distributed_11/Reshape_1/shape\n",
"time_distributed_11/Reshape_1\n",
"time_distributed_12/Reshape/shape\n",
"time_distributed_12/Reshape\n",
"time_distributed_12/MaxPool\n",
"time_distributed_12/Reshape_1/shape\n",
"time_distributed_12/Reshape_1\n",
"time_distributed_13/Reshape/shape\n",
"time_distributed_13/Reshape\n",
"time_distributed_13/keras_learning_phase/input\n",
"time_distributed_13/keras_learning_phase\n",
"time_distributed_13/cond/Switch\n",
"time_distributed_13/cond/switch_t\n",
"time_distributed_13/cond/pred_id\n",
"time_distributed_13/cond/mul/y\n",
"time_distributed_13/cond/mul\n",
"time_distributed_13/cond/mul/Switch\n",
"time_distributed_13/cond/dropout/keep_prob\n",
"time_distributed_13/cond/dropout/Shape\n",
"time_distributed_13/cond/dropout/random_uniform/min\n",
"time_distributed_13/cond/dropout/random_uniform/max\n",
"time_distributed_13/cond/dropout/random_uniform/RandomUniform\n",
"time_distributed_13/cond/dropout/random_uniform/sub\n",
"time_distributed_13/cond/dropout/random_uniform/mul\n",
"time_distributed_13/cond/dropout/random_uniform\n",
"time_distributed_13/cond/dropout/add\n",
"time_distributed_13/cond/dropout/Floor\n",
"time_distributed_13/cond/dropout/div\n",
"time_distributed_13/cond/dropout/mul\n",
"time_distributed_13/cond/Switch_1\n",
"time_distributed_13/cond/Merge\n",
"time_distributed_13/Reshape_1/shape\n",
"time_distributed_13/Reshape_1\n",
"time_distributed_14/kernel\n",
"time_distributed_14/kernel/read\n",
"time_distributed_14/bias\n",
"time_distributed_14/bias/read\n",
"time_distributed_14/Reshape/shape\n",
"time_distributed_14/Reshape\n",
"time_distributed_14/convolution\n",
"time_distributed_14/BiasAdd\n",
"time_distributed_14/Relu\n",
"time_distributed_14/Reshape_1/shape\n",
"time_distributed_14/Reshape_1\n",
"time_distributed_15/kernel\n",
"time_distributed_15/kernel/read\n",
"time_distributed_15/bias\n",
"time_distributed_15/bias/read\n",
"time_distributed_15/Reshape/shape\n",
"time_distributed_15/Reshape\n",
"time_distributed_15/convolution\n",
"time_distributed_15/BiasAdd\n",
"time_distributed_15/Relu\n",
"time_distributed_15/Reshape_1/shape\n",
"time_distributed_15/Reshape_1\n",
"time_distributed_16/Reshape/shape\n",
"time_distributed_16/Reshape\n",
"time_distributed_16/MaxPool\n",
"time_distributed_16/Reshape_1/shape\n",
"time_distributed_16/Reshape_1\n",
"time_distributed_17/Reshape/shape\n",
"time_distributed_17/Reshape\n",
"time_distributed_17/cond/Switch\n",
"time_distributed_17/cond/switch_t\n",
"time_distributed_17/cond/pred_id\n",
"time_distributed_17/cond/mul/y\n",
"time_distributed_17/cond/mul\n",
"time_distributed_17/cond/mul/Switch\n",
"time_distributed_17/cond/dropout/keep_prob\n",
"time_distributed_17/cond/dropout/Shape\n",
"time_distributed_17/cond/dropout/random_uniform/min\n",
"time_distributed_17/cond/dropout/random_uniform/max\n",
"time_distributed_17/cond/dropout/random_uniform/RandomUniform\n",
"time_distributed_17/cond/dropout/random_uniform/sub\n",
"time_distributed_17/cond/dropout/random_uniform/mul\n",
"time_distributed_17/cond/dropout/random_uniform\n",
"time_distributed_17/cond/dropout/add\n",
"time_distributed_17/cond/dropout/Floor\n",
"time_distributed_17/cond/dropout/div\n",
"time_distributed_17/cond/dropout/mul\n",
"time_distributed_17/cond/Switch_1\n",
"time_distributed_17/cond/Merge\n",
"time_distributed_17/Reshape_1/shape\n",
"time_distributed_17/Reshape_1\n",
"time_distributed_18/Reshape/shape\n",
"time_distributed_18/Reshape\n",
"time_distributed_18/Shape\n",
"time_distributed_18/strided_slice/stack\n",
"time_distributed_18/strided_slice/stack_1\n",
"time_distributed_18/strided_slice/stack_2\n",
"time_distributed_18/strided_slice\n",
"time_distributed_18/Const\n",
"time_distributed_18/Prod\n",
"time_distributed_18/stack/0\n",
"time_distributed_18/stack\n",
"time_distributed_18/Reshape_1\n",
"time_distributed_18/Reshape_2/shape\n",
"time_distributed_18/Reshape_2\n",
"lstm_3/kernel\n",
"lstm_3/kernel/read\n",
"lstm_3/recurrent_kernel\n",
"lstm_3/recurrent_kernel/read\n",
"lstm_3/bias\n",
"lstm_3/bias/read\n",
"lstm_3/strided_slice/stack\n",
"lstm_3/strided_slice/stack_1\n",
"lstm_3/strided_slice/stack_2\n",
"lstm_3/strided_slice\n",
"lstm_3/strided_slice_1/stack\n",
"lstm_3/strided_slice_1/stack_1\n",
"lstm_3/strided_slice_1/stack_2\n",
"lstm_3/strided_slice_1\n",
"lstm_3/strided_slice_2/stack\n",
"lstm_3/strided_slice_2/stack_1\n",
"lstm_3/strided_slice_2/stack_2\n",
"lstm_3/strided_slice_2\n",
"lstm_3/strided_slice_3/stack\n",
"lstm_3/strided_slice_3/stack_1\n",
"lstm_3/strided_slice_3/stack_2\n",
"lstm_3/strided_slice_3\n",
"lstm_3/strided_slice_4/stack\n",
"lstm_3/strided_slice_4/stack_1\n",
"lstm_3/strided_slice_4/stack_2\n",
"lstm_3/strided_slice_4\n",
"lstm_3/strided_slice_5/stack\n",
"lstm_3/strided_slice_5/stack_1\n",
"lstm_3/strided_slice_5/stack_2\n",
"lstm_3/strided_slice_5\n",
"lstm_3/strided_slice_6/stack\n",
"lstm_3/strided_slice_6/stack_1\n",
"lstm_3/strided_slice_6/stack_2\n",
"lstm_3/strided_slice_6\n",
"lstm_3/strided_slice_7/stack\n",
"lstm_3/strided_slice_7/stack_1\n",
"lstm_3/strided_slice_7/stack_2\n",
"lstm_3/strided_slice_7\n",
"lstm_3/strided_slice_8/stack\n",
"lstm_3/strided_slice_8/stack_1\n",
"lstm_3/strided_slice_8/stack_2\n",
"lstm_3/strided_slice_8\n",
"lstm_3/strided_slice_9/stack\n",
"lstm_3/strided_slice_9/stack_1\n",
"lstm_3/strided_slice_9/stack_2\n",
"lstm_3/strided_slice_9\n",
"lstm_3/strided_slice_10/stack\n",
"lstm_3/strided_slice_10/stack_1\n",
"lstm_3/strided_slice_10/stack_2\n",
"lstm_3/strided_slice_10\n",
"lstm_3/strided_slice_11/stack\n",
"lstm_3/strided_slice_11/stack_1\n",
"lstm_3/strided_slice_11/stack_2\n",
"lstm_3/strided_slice_11\n",
"lstm_3/zeros_like\n",
"lstm_3/Sum/reduction_indices\n",
"lstm_3/Sum\n",
"lstm_3/ExpandDims/dim\n",
"lstm_3/ExpandDims\n",
"lstm_3/Tile/multiples\n",
"lstm_3/Tile\n",
"lstm_3/Tile_1/multiples\n",
"lstm_3/Tile_1\n",
"lstm_3/transpose/perm\n",
"lstm_3/transpose\n",
"lstm_3/Shape\n",
"lstm_3/strided_slice_12/stack\n",
"lstm_3/strided_slice_12/stack_1\n",
"lstm_3/strided_slice_12/stack_2\n",
"lstm_3/strided_slice_12\n",
"lstm_3/TensorArray\n",
"lstm_3/TensorArray_1\n",
"lstm_3/TensorArrayUnstack/Shape\n",
"lstm_3/TensorArrayUnstack/strided_slice/stack\n",
"lstm_3/TensorArrayUnstack/strided_slice/stack_1\n",
"lstm_3/TensorArrayUnstack/strided_slice/stack_2\n",
"lstm_3/TensorArrayUnstack/strided_slice\n",
"lstm_3/TensorArrayUnstack/range/start\n",
"lstm_3/TensorArrayUnstack/range/delta\n",
"lstm_3/TensorArrayUnstack/range\n",
"lstm_3/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3\n",
"lstm_3/time\n",
"lstm_3/while/maximum_iterations\n",
"lstm_3/while/iteration_counter\n",
"lstm_3/while/Enter\n",
"lstm_3/while/Enter_1\n",
"lstm_3/while/Enter_2\n",
"lstm_3/while/Enter_3\n",
"lstm_3/while/Enter_4\n",
"lstm_3/while/Merge\n",
"lstm_3/while/Merge_1\n",
"lstm_3/while/Merge_2\n",
"lstm_3/while/Merge_3\n",
"lstm_3/while/Merge_4\n",
"lstm_3/while/Less\n",
"lstm_3/while/Less/Enter\n",
"lstm_3/while/Less_1\n",
"lstm_3/while/Less_1/Enter\n",
"lstm_3/while/LogicalAnd\n",
"lstm_3/while/LoopCond\n",
"lstm_3/while/Switch\n",
"lstm_3/while/Switch_1\n",
"lstm_3/while/Switch_2\n",
"lstm_3/while/Switch_3\n",
"lstm_3/while/Switch_4\n",
"lstm_3/while/Identity\n",
"lstm_3/while/Identity_1\n",
"lstm_3/while/Identity_2\n",
"lstm_3/while/Identity_3\n",
"lstm_3/while/Identity_4\n",
"lstm_3/while/add/y\n",
"lstm_3/while/add\n",
"lstm_3/while/TensorArrayReadV3\n",
"lstm_3/while/TensorArrayReadV3/Enter\n",
"lstm_3/while/TensorArrayReadV3/Enter_1\n",
"lstm_3/while/MatMul\n",
"lstm_3/while/MatMul/Enter\n",
"lstm_3/while/MatMul_1\n",
"lstm_3/while/MatMul_1/Enter\n",
"lstm_3/while/MatMul_2\n",
"lstm_3/while/MatMul_2/Enter\n",
"lstm_3/while/MatMul_3\n",
"lstm_3/while/MatMul_3/Enter\n",
"lstm_3/while/BiasAdd\n",
"lstm_3/while/BiasAdd/Enter\n",
"lstm_3/while/BiasAdd_1\n",
"lstm_3/while/BiasAdd_1/Enter\n",
"lstm_3/while/BiasAdd_2\n",
"lstm_3/while/BiasAdd_2/Enter\n",
"lstm_3/while/BiasAdd_3\n",
"lstm_3/while/BiasAdd_3/Enter\n",
"lstm_3/while/MatMul_4\n",
"lstm_3/while/MatMul_4/Enter\n",
"lstm_3/while/add_1\n",
"lstm_3/while/mul/x\n",
"lstm_3/while/mul\n",
"lstm_3/while/add_2/y\n",
"lstm_3/while/add_2\n",
"lstm_3/while/Const\n",
"lstm_3/while/Const_1\n",
"lstm_3/while/clip_by_value/Minimum\n",
"lstm_3/while/clip_by_value\n",
"lstm_3/while/MatMul_5\n",
"lstm_3/while/MatMul_5/Enter\n",
"lstm_3/while/add_3\n",
"lstm_3/while/mul_1/x\n",
"lstm_3/while/mul_1\n",
"lstm_3/while/add_4/y\n",
"lstm_3/while/add_4\n",
"lstm_3/while/Const_2\n",
"lstm_3/while/Const_3\n",
"lstm_3/while/clip_by_value_1/Minimum\n",
"lstm_3/while/clip_by_value_1\n",
"lstm_3/while/mul_2\n",
"lstm_3/while/MatMul_6\n",
"lstm_3/while/MatMul_6/Enter\n",
"lstm_3/while/add_5\n",
"lstm_3/while/Tanh\n",
"lstm_3/while/mul_3\n",
"lstm_3/while/add_6\n",
"lstm_3/while/MatMul_7\n",
"lstm_3/while/MatMul_7/Enter\n",
"lstm_3/while/add_7\n",
"lstm_3/while/mul_4/x\n",
"lstm_3/while/mul_4\n",
"lstm_3/while/add_8/y\n",
"lstm_3/while/add_8\n",
"lstm_3/while/Const_4\n",
"lstm_3/while/Const_5\n",
"lstm_3/while/clip_by_value_2/Minimum\n",
"lstm_3/while/clip_by_value_2\n",
"lstm_3/while/Tanh_1\n",
"lstm_3/while/mul_5\n",
"lstm_3/while/TensorArrayWrite/TensorArrayWriteV3\n",
"lstm_3/while/TensorArrayWrite/TensorArrayWriteV3/Enter\n",
"lstm_3/while/add_9/y\n",
"lstm_3/while/add_9\n",
"lstm_3/while/NextIteration\n",
"lstm_3/while/NextIteration_1\n",
"lstm_3/while/NextIteration_2\n",
"lstm_3/while/NextIteration_3\n",
"lstm_3/while/NextIteration_4\n",
"lstm_3/while/Exit_2\n",
"lstm_3/TensorArrayStack/TensorArraySizeV3\n",
"lstm_3/TensorArrayStack/range/start\n",
"lstm_3/TensorArrayStack/range/delta\n",
"lstm_3/TensorArrayStack/range\n",
"lstm_3/TensorArrayStack/TensorArrayGatherV3\n",
"lstm_3/transpose_1/perm\n",
"lstm_3/transpose_1\n",
"dropout_7/cond/Switch\n",
"dropout_7/cond/switch_t\n",
"dropout_7/cond/pred_id\n",
"dropout_7/cond/mul/y\n",
"dropout_7/cond/mul\n",
"dropout_7/cond/mul/Switch\n",
"dropout_7/cond/dropout/keep_prob\n",
"dropout_7/cond/dropout/Shape\n",
"dropout_7/cond/dropout/random_uniform/min\n",
"dropout_7/cond/dropout/random_uniform/max\n",
"dropout_7/cond/dropout/random_uniform/RandomUniform\n",
"dropout_7/cond/dropout/random_uniform/sub\n",
"dropout_7/cond/dropout/random_uniform/mul\n",
"dropout_7/cond/dropout/random_uniform\n",
"dropout_7/cond/dropout/add\n",
"dropout_7/cond/dropout/Floor\n",
"dropout_7/cond/dropout/div\n",
"dropout_7/cond/dropout/mul\n",
"dropout_7/cond/Switch_1\n",
"dropout_7/cond/Merge\n",
"lstm_4/kernel\n",
"lstm_4/kernel/read\n",
"lstm_4/recurrent_kernel\n",
"lstm_4/recurrent_kernel/read\n",
"lstm_4/bias\n",
"lstm_4/bias/read\n",
"lstm_4/strided_slice/stack\n",
"lstm_4/strided_slice/stack_1\n",
"lstm_4/strided_slice/stack_2\n",
"lstm_4/strided_slice\n",
"lstm_4/strided_slice_1/stack\n",
"lstm_4/strided_slice_1/stack_1\n",
"lstm_4/strided_slice_1/stack_2\n",
"lstm_4/strided_slice_1\n",
"lstm_4/strided_slice_2/stack\n",
"lstm_4/strided_slice_2/stack_1\n",
"lstm_4/strided_slice_2/stack_2\n",
"lstm_4/strided_slice_2\n",
"lstm_4/strided_slice_3/stack\n",
"lstm_4/strided_slice_3/stack_1\n",
"lstm_4/strided_slice_3/stack_2\n",
"lstm_4/strided_slice_3\n",
"lstm_4/strided_slice_4/stack\n",
"lstm_4/strided_slice_4/stack_1\n",
"lstm_4/strided_slice_4/stack_2\n",
"lstm_4/strided_slice_4\n",
"lstm_4/strided_slice_5/stack\n",
"lstm_4/strided_slice_5/stack_1\n",
"lstm_4/strided_slice_5/stack_2\n",
"lstm_4/strided_slice_5\n",
"lstm_4/strided_slice_6/stack\n",
"lstm_4/strided_slice_6/stack_1\n",
"lstm_4/strided_slice_6/stack_2\n",
"lstm_4/strided_slice_6\n",
"lstm_4/strided_slice_7/stack\n",
"lstm_4/strided_slice_7/stack_1\n",
"lstm_4/strided_slice_7/stack_2\n",
"lstm_4/strided_slice_7\n",
"lstm_4/strided_slice_8/stack\n",
"lstm_4/strided_slice_8/stack_1\n",
"lstm_4/strided_slice_8/stack_2\n",
"lstm_4/strided_slice_8\n",
"lstm_4/strided_slice_9/stack\n",
"lstm_4/strided_slice_9/stack_1\n",
"lstm_4/strided_slice_9/stack_2\n",
"lstm_4/strided_slice_9\n",
"lstm_4/strided_slice_10/stack\n",
"lstm_4/strided_slice_10/stack_1\n",
"lstm_4/strided_slice_10/stack_2\n",
"lstm_4/strided_slice_10\n",
"lstm_4/strided_slice_11/stack\n",
"lstm_4/strided_slice_11/stack_1\n",
"lstm_4/strided_slice_11/stack_2\n",
"lstm_4/strided_slice_11\n",
"lstm_4/zeros_like\n",
"lstm_4/Sum/reduction_indices\n",
"lstm_4/Sum\n",
"lstm_4/ExpandDims/dim\n",
"lstm_4/ExpandDims\n",
"lstm_4/Tile/multiples\n",
"lstm_4/Tile\n",
"lstm_4/Tile_1/multiples\n",
"lstm_4/Tile_1\n",
"lstm_4/transpose/perm\n",
"lstm_4/transpose\n",
"lstm_4/Shape\n",
"lstm_4/strided_slice_12/stack\n",
"lstm_4/strided_slice_12/stack_1\n",
"lstm_4/strided_slice_12/stack_2\n",
"lstm_4/strided_slice_12\n",
"lstm_4/TensorArray\n",
"lstm_4/TensorArray_1\n",
"lstm_4/TensorArrayUnstack/Shape\n",
"lstm_4/TensorArrayUnstack/strided_slice/stack\n",
"lstm_4/TensorArrayUnstack/strided_slice/stack_1\n",
"lstm_4/TensorArrayUnstack/strided_slice/stack_2\n",
"lstm_4/TensorArrayUnstack/strided_slice\n",
"lstm_4/TensorArrayUnstack/range/start\n",
"lstm_4/TensorArrayUnstack/range/delta\n",
"lstm_4/TensorArrayUnstack/range\n",
"lstm_4/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3\n",
"lstm_4/time\n",
"lstm_4/while/maximum_iterations\n",
"lstm_4/while/iteration_counter\n",
"lstm_4/while/Enter\n",
"lstm_4/while/Enter_1\n",
"lstm_4/while/Enter_2\n",
"lstm_4/while/Enter_3\n",
"lstm_4/while/Enter_4\n",
"lstm_4/while/Merge\n",
"lstm_4/while/Merge_1\n",
"lstm_4/while/Merge_2\n",
"lstm_4/while/Merge_3\n",
"lstm_4/while/Merge_4\n",
"lstm_4/while/Less\n",
"lstm_4/while/Less/Enter\n",
"lstm_4/while/Less_1\n",
"lstm_4/while/Less_1/Enter\n",
"lstm_4/while/LogicalAnd\n",
"lstm_4/while/LoopCond\n",
"lstm_4/while/Switch\n",
"lstm_4/while/Switch_1\n",
"lstm_4/while/Switch_2\n",
"lstm_4/while/Switch_3\n",
"lstm_4/while/Switch_4\n",
"lstm_4/while/Identity\n",
"lstm_4/while/Identity_1\n",
"lstm_4/while/Identity_2\n",
"lstm_4/while/Identity_3\n",
"lstm_4/while/Identity_4\n",
"lstm_4/while/add/y\n",
"lstm_4/while/add\n",
"lstm_4/while/TensorArrayReadV3\n",
"lstm_4/while/TensorArrayReadV3/Enter\n",
"lstm_4/while/TensorArrayReadV3/Enter_1\n",
"lstm_4/while/MatMul\n",
"lstm_4/while/MatMul/Enter\n",
"lstm_4/while/MatMul_1\n",
"lstm_4/while/MatMul_1/Enter\n",
"lstm_4/while/MatMul_2\n",
"lstm_4/while/MatMul_2/Enter\n",
"lstm_4/while/MatMul_3\n",
"lstm_4/while/MatMul_3/Enter\n",
"lstm_4/while/BiasAdd\n",
"lstm_4/while/BiasAdd/Enter\n",
"lstm_4/while/BiasAdd_1\n",
"lstm_4/while/BiasAdd_1/Enter\n",
"lstm_4/while/BiasAdd_2\n",
"lstm_4/while/BiasAdd_2/Enter\n",
"lstm_4/while/BiasAdd_3\n",
"lstm_4/while/BiasAdd_3/Enter\n",
"lstm_4/while/MatMul_4\n",
"lstm_4/while/MatMul_4/Enter\n",
"lstm_4/while/add_1\n",
"lstm_4/while/mul/x\n",
"lstm_4/while/mul\n",
"lstm_4/while/add_2/y\n",
"lstm_4/while/add_2\n",
"lstm_4/while/Const\n",
"lstm_4/while/Const_1\n",
"lstm_4/while/clip_by_value/Minimum\n",
"lstm_4/while/clip_by_value\n",
"lstm_4/while/MatMul_5\n",
"lstm_4/while/MatMul_5/Enter\n",
"lstm_4/while/add_3\n",
"lstm_4/while/mul_1/x\n",
"lstm_4/while/mul_1\n",
"lstm_4/while/add_4/y\n",
"lstm_4/while/add_4\n",
"lstm_4/while/Const_2\n",
"lstm_4/while/Const_3\n",
"lstm_4/while/clip_by_value_1/Minimum\n",
"lstm_4/while/clip_by_value_1\n",
"lstm_4/while/mul_2\n",
"lstm_4/while/MatMul_6\n",
"lstm_4/while/MatMul_6/Enter\n",
"lstm_4/while/add_5\n",
"lstm_4/while/Tanh\n",
"lstm_4/while/mul_3\n",
"lstm_4/while/add_6\n",
"lstm_4/while/MatMul_7\n",
"lstm_4/while/MatMul_7/Enter\n",
"lstm_4/while/add_7\n",
"lstm_4/while/mul_4/x\n",
"lstm_4/while/mul_4\n",
"lstm_4/while/add_8/y\n",
"lstm_4/while/add_8\n",
"lstm_4/while/Const_4\n",
"lstm_4/while/Const_5\n",
"lstm_4/while/clip_by_value_2/Minimum\n",
"lstm_4/while/clip_by_value_2\n",
"lstm_4/while/Tanh_1\n",
"lstm_4/while/mul_5\n",
"lstm_4/while/TensorArrayWrite/TensorArrayWriteV3\n",
"lstm_4/while/TensorArrayWrite/TensorArrayWriteV3/Enter\n",
"lstm_4/while/add_9/y\n",
"lstm_4/while/add_9\n",
"lstm_4/while/NextIteration\n",
"lstm_4/while/NextIteration_1\n",
"lstm_4/while/NextIteration_2\n",
"lstm_4/while/NextIteration_3\n",
"lstm_4/while/NextIteration_4\n",
"lstm_4/while/Exit_1\n",
"lstm_4/while/Exit_2\n",
"lstm_4/sub/y\n",
"lstm_4/sub\n",
"lstm_4/TensorArrayReadV3\n",
"dropout_8/cond/Switch\n",
"dropout_8/cond/switch_t\n",
"dropout_8/cond/pred_id\n",
"dropout_8/cond/mul/y\n",
"dropout_8/cond/mul\n",
"dropout_8/cond/mul/Switch\n",
"dropout_8/cond/dropout/keep_prob\n",
"dropout_8/cond/dropout/Shape\n",
"dropout_8/cond/dropout/random_uniform/min\n",
"dropout_8/cond/dropout/random_uniform/max\n",
"dropout_8/cond/dropout/random_uniform/RandomUniform\n",
"dropout_8/cond/dropout/random_uniform/sub\n",
"dropout_8/cond/dropout/random_uniform/mul\n",
"dropout_8/cond/dropout/random_uniform\n",
"dropout_8/cond/dropout/add\n",
"dropout_8/cond/dropout/Floor\n",
"dropout_8/cond/dropout/div\n",
"dropout_8/cond/dropout/mul\n",
"dropout_8/cond/Switch_1\n",
"dropout_8/cond/Merge\n",
"dense_2/kernel\n",
"dense_2/kernel/read\n",
"dense_2/bias\n",
"dense_2/bias/read\n",
"dense_2/MatMul\n",
"dense_2/BiasAdd\n",
"dense_2/Softmax\n",
"output_node0\n",
"\n"
]
}
],
"source": [
"g = tf.GraphDef()\n",
"g.ParseFromString(open(output_path + output_file, \"rb\").read())\n",
"s = \"\"\n",
"for n in g.node:\n",
" s =s + str(n.name) + \"\\n\"\n",
"\n",
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Froze 16 variables.\n",
"INFO:tensorflow:Converted 16 variables to const ops.\n",
"Saved the freezed graph at: ./Models/LSTM.pb\n"
]
}
],
"source": [
"from tensorflow.python.framework import graph_util\n",
"from tensorflow.python.framework import graph_io\n",
"constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), pred_node_names)\n",
"\n",
"graph_io.write_graph(constant_graph, output_path, output_file, as_text=False)\n",
"\n",
"print('Saved the freezed graph at: ', (output_path + output_file))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}