Deep-Learning-Course/ComputationalGraphs.ipynb

1084 lines
432 KiB
Plaintext
Raw Normal View History

2017-10-08 09:42:12 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Computational Graphs (Basics)\n",
"\n",
"## What is a computational graph?\n",
"\n",
"Computational graph is a graphical representation of numerical computations. The mathematical operations are captured as nodes. The data flowing as input and output of the nodes is represented by the edges connecting them. \n",
"\n",
"## Why computational graphs?\n",
"\n",
"Computational graphs provide a way to *define* the computations that need to be done. They are like a visual programming language (declarative language). Once the computation is described, the libraries like Tensorflow and Theano, can execute them depending on the device configurations where the computation is executed. Thus once defined the computation can be run on CPUs, a distributed network of CPUs, GPUs, mobile phones etc.\n",
"\n",
"## Computational graph in Tensorflow\n",
"\n",
"In Tensorflow, you can use Python language to programmatically build a computational graph. Inputs for the graph are defined as placeholders and they are supplied at the time of executing the computations. To compute on the graph, a Tensorflow session is created and input data is provided. If you execute the run and provide the nodes whose values you seek as output. Tensorflow finds all *dependent* computation nodes necessary to compute the values of output nodes, and executes the computation only for the necessary paths. \n",
"\n",
"We will see in later sessions how more advanced computing is done in the context of neural networks, and also understand how Tensorflow computational graph provides automatic differentiation, necessary for learning algorithms like backpropagation."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from graphviz import Digraph\n",
"from IPython.core.display import display, SVG\n",
"\n",
"def tf_to_dot(graph):\n",
" dot = Digraph()\n",
"\n",
" for n in graph.as_graph_def().node:\n",
" name = n.name.split('/')[0]\n",
" dot.node(name, label=name)\n",
"\n",
" for src in n.input:\n",
" src = src.split('/')[0]\n",
" if src != name:\n",
" dot.edge(src, name)\n",
" display(SVG(dot._repr_svg_())) \n",
" return dot"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"116pt\" viewBox=\"0.00 0.00 141.55 116.00\" width=\"142pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 112)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"#ffffff\" points=\"-4,4 -4,-112 137.5473,-112 137.5473,4 -4,4\" stroke=\"transparent\"/>\n",
"<!-- a___ -->\n",
"<g class=\"node\" id=\"node1\">\n",
"<title>a___</title>\n",
"<ellipse cx=\"30.5473\" cy=\"-90\" fill=\"none\" rx=\"30.5947\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"30.5473\" y=\"-86.3\">a___</text>\n",
"</g>\n",
"<!-- addition -->\n",
"<g class=\"node\" id=\"node3\">\n",
"<title>addition</title>\n",
"<ellipse cx=\"68.5473\" cy=\"-18\" fill=\"none\" rx=\"48.9926\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"68.5473\" y=\"-14.3\">addition</text>\n",
"</g>\n",
"<!-- a___&#45;&gt;addition -->\n",
"<g class=\"edge\" id=\"edge1\">\n",
"<title>a___-&gt;addition</title>\n",
"<path d=\"M39.746,-72.5708C44.161,-64.2055 49.5484,-53.998 54.4641,-44.6839\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"57.597,-46.2464 59.1693,-35.7689 51.4063,-42.9791 57.597,-46.2464\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- b -->\n",
"<g class=\"node\" id=\"node2\">\n",
"<title>b</title>\n",
"<ellipse cx=\"106.5473\" cy=\"-90\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"106.5473\" y=\"-86.3\">b</text>\n",
"</g>\n",
"<!-- b&#45;&gt;addition -->\n",
"<g class=\"edge\" id=\"edge2\">\n",
"<title>b-&gt;addition</title>\n",
"<path d=\"M97.5418,-72.937C93.0975,-64.5161 87.6331,-54.1627 82.6509,-44.7226\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"85.6479,-42.9026 77.885,-35.6924 79.4572,-46.17 85.6479,-42.9026\" stroke=\"#000000\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"16.0\n"
]
}
],
"source": [
"import tensorflow as tf\n",
"\n",
"tf.reset_default_graph()\n",
"\n",
"node_a = tf.placeholder(dtype=tf.float32,name=\"a___\")\n",
"node_b = tf.constant(6.0,dtype=tf.float32, name=\"b\")\n",
"\n",
"adder_node = tf.add(node_a,node_b, name=\"addition\")\n",
"\n",
"\n",
"sess = tf.Session()\n",
"output = sess.run(adder_node,{node_a:10.0})\n",
"tf_to_dot(tf.get_default_graph())\n",
"sess.close()\n",
"\n",
"print output"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAD8CAYAAAB9y7/cAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzsvM+vbVt23/UZY865fux99vlx730/6r2qVFVsyy6X7cQN\nSANhAsJAoEGHIIxEB4GREAgJOkjAP0AvSouAaNCKFIFoAt0YGgkYHBxL/oFju8qu9169++Ocs/de\nP+acY9CY65x7q1IWkMpTitIZ0tXd++y1115rrjnH/I7v+I4h7s6TPdmTPdmT/fiZ/qO+gCd7sid7\nsif7YuzJwT/Zkz3Zk/2Y2pODf7Ine7In+zG1Jwf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48B5LUjs6PuAF2M6F6oYsXP2+x19f8FUM3N2RJWb6z0lG9NpRsNInxqFN5eFsevAAnXNuAmmRtJA\nlMBSF/ouNRpIKikKHkfqdEcgoCHg1XCFEB0vGVcnhB7DseDEUAmdYrWSaWMWkzOECLWACoKiGgi7\nyPm4cHV5Qd8rtTh1NTQpwZXzeWLORjWhTxBiolKJKF5n8hQxh16h6wdMnHl1EEEloKLksmJSqRIY\nohOkB1sp1XCbsJrwmHFLWF1RMUwjttE7a55REUJKBBFcGwxTjY1W6xSVwOH5e8xTpp5f4sUQEqKg\nKbRoSB1zpe92EIRSJ+o8fQ878Q9qX4iDd/ciIv8e8D8CAfiv3f3v/mnHC1C9ohJ4S669dfSPDp/G\nVT5YCIEHfszcEI+YVMRTc+4ScQpWH+lAam10B2q4GeqCamo0jsQtOnigQyLU2qKKRtRixC1k284D\nRIngRkQo7khQMMG8oRP
"text/plain": [
"<matplotlib.figure.Figure at 0x7efb9463dad0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAD8CAYAAAB9y7/cAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzsvWlsrNl53/l/ayNrZbG4Fe/l5d2afdtSt9QSOi1FPUlk\nOzOYmXQsx1YS2wgcB7Y7gewglpXYDuAP81H5EAEDjDEZAQ5mYkTxOB8mVoLARhY5RmxZ0WZ1q6Xu\nu/TdebkUWcVisfaqdz6wfw+fOreupHS34IsGD0CQrOV9z3uW//N//s9zzoniONZpOS2n5bSclndf\nSfxZV+C0nJbTclpOy/ennAL8aTktp+W0vEvLKcCfltNyWk7Lu7ScAvxpOS2n5bS8S8spwJ+W03Ja\nTsu7tJwC/Gk5LafltLxLy/cN4KMo+p+jKHo9iqLrURT92vfrPqfltJyW03Jappfo+5EHH0VRUtJV\nSf+jpHuSvizpJ+M4/tY7frPTclpOy2k5LVPL94vBPy/pehzHb8R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gPLhOv9+fCGghz5w5c0atVmtC+xyNRmq1Wpqfn5ckHR0d2USiHwCK8XisfD5v\nQJzNZtXpdJRKpVQqlcyIN5vNiZgCQMu4CQPAsP+joyPzIGDS0onnwZiQZCAKoLbbbWszAAnQI1aQ\nSqXsPkgasHbqhgdQLBYtloX+PhgMVCwWrX25rpeLeC7GvzdCeCuhhxkSFz9WU6mUATDF19fLp4A9\n3h33QZqjv/28DL185iP1xoMK9X+eDQ9Gksk/nU7HyAB14fve42DOeQ2ePkK7z2QyymazKhQKpt17\n8G632yoWi2YcGDvj8Vg
"text/plain": [
"<matplotlib.figure.Figure at 0x7efb981645d0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"<svg height=\"332pt\" viewBox=\"0.00 0.00 248.14 332.00\" width=\"248pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 328)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"#ffffff\" points=\"-4,4 -4,-328 244.1401,-328 244.1401,4 -4,4\" stroke=\"transparent\"/>\n",
"<!-- to_float -->\n",
"<g class=\"node\" id=\"node1\">\n",
"<title>to_float</title>\n",
"<ellipse cx=\"63.6943\" cy=\"-306\" fill=\"none\" rx=\"46.2923\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"63.6943\" y=\"-302.3\">to_float</text>\n",
"</g>\n",
"<!-- div_by_255 -->\n",
"<g class=\"node\" id=\"node2\">\n",
"<title>div_by_255</title>\n",
"<ellipse cx=\"63.6943\" cy=\"-234\" fill=\"none\" rx=\"63.8893\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"63.6943\" y=\"-230.3\">div_by_255</text>\n",
"</g>\n",
"<!-- to_float&#45;&gt;div_by_255 -->\n",
"<g class=\"edge\" id=\"edge1\">\n",
"<title>to_float-&gt;div_by_255</title>\n",
"<path d=\"M63.6943,-287.8314C63.6943,-280.131 63.6943,-270.9743 63.6943,-262.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"67.1944,-262.4132 63.6943,-252.4133 60.1944,-262.4133 67.1944,-262.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- dot -->\n",
"<g class=\"node\" id=\"node4\">\n",
"<title>dot</title>\n",
"<ellipse cx=\"127.6943\" cy=\"-162\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"127.6943\" y=\"-158.3\">dot</text>\n",
"</g>\n",
"<!-- div_by_255&#45;&gt;dot -->\n",
"<g class=\"edge\" id=\"edge2\">\n",
"<title>div_by_255-&gt;dot</title>\n",
"<path d=\"M79.5146,-216.2022C87.8096,-206.8703 98.0731,-195.3239 106.9929,-185.2892\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"109.7672,-187.4362 113.795,-177.6368 104.5354,-182.7856 109.7672,-187.4362\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- weights -->\n",
"<g class=\"node\" id=\"node3\">\n",
"<title>weights</title>\n",
"<ellipse cx=\"192.6943\" cy=\"-234\" fill=\"none\" rx=\"47.3916\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"192.6943\" y=\"-230.3\">weights</text>\n",
"</g>\n",
"<!-- weights&#45;&gt;dot -->\n",
"<g class=\"edge\" id=\"edge3\">\n",
"<title>weights-&gt;dot</title>\n",
"<path d=\"M177.2903,-216.937C168.6744,-207.3933 157.8177,-195.3674 148.4601,-185.002\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"150.9574,-182.5452 141.6584,-177.4679 145.7616,-187.236 150.9574,-182.5452\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_by_255 -->\n",
"<g class=\"node\" id=\"node5\">\n",
"<title>mul_by_255</title>\n",
"<ellipse cx=\"127.6943\" cy=\"-90\" fill=\"none\" rx=\"66.8882\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"127.6943\" y=\"-86.3\">mul_by_255</text>\n",
"</g>\n",
"<!-- dot&#45;&gt;mul_by_255 -->\n",
"<g class=\"edge\" id=\"edge4\">\n",
"<title>dot-&gt;mul_by_255</title>\n",
"<path d=\"M127.6943,-143.8314C127.6943,-136.131 127.6943,-126.9743 127.6943,-118.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"131.1944,-118.4132 127.6943,-108.4133 124.1944,-118.4133 131.1944,-118.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- to_uint8 -->\n",
"<g class=\"node\" id=\"node6\">\n",
"<title>to_uint8</title>\n",
"<ellipse cx=\"127.6943\" cy=\"-18\" fill=\"none\" rx=\"49.2915\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"127.6943\" y=\"-14.3\">to_uint8</text>\n",
"</g>\n",
"<!-- mul_by_255&#45;&gt;to_uint8 -->\n",
"<g class=\"edge\" id=\"edge5\">\n",
"<title>mul_by_255-&gt;to_uint8</title>\n",
"<path d=\"M127.6943,-71.8314C127.6943,-64.131 127.6943,-54.9743 127.6943,-46.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"131.1944,-46.4132 127.6943,-36.4133 124.1944,-46.4133 131.1944,-46.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from skimage import data as imgdata\n",
"import skimage.color as color\n",
"import matplotlib.pyplot as plt\n",
"import scipy.ndimage as ndimage\n",
"import numpy as np\n",
"\n",
"coffee_cup = imgdata.coffee()\n",
"plt.imshow(coffee_cup)\n",
"plt.show()\n",
"\n",
"def to_gray(img):\n",
" #img = tf.placeholder(tf.uint8,name=\"input____\")\n",
" img_float = tf.div(tf.cast(img,dtype=tf.float64,name=\"to_float\"),255.0,name='div_by_255')\n",
" weights = tf.constant([0.2125,0.7154,0.0721],dtype=tf.float64,name=\"weights\")\n",
" \n",
"# R = tf.slice(img_float,[0,0,0],[-1,-1,1],name='extract_red')\n",
"# G = tf.slice(img_float,[0,0,1],[-1,-1,1],name='extract_green')\n",
"# B = tf.slice(img_float,[0,0,2],[-1,-1,1],name='extract_blue')\n",
" \n",
" \n",
"# gray = 0.2125*R + 0.7154*G + 0.0721*B\n",
" gray = tf.tensordot(img_float,weights,axes=1,name=\"dot\")\n",
"# weighted = tf.multiply(img_float,weights,name=\"weighting\")\n",
"# gray = tf.reduce_sum(weighted,axis=2, name =\"weighted_sum\") \n",
" \n",
" output = tf.cast(tf.multiply(gray,255.0,name='mul_by_255'), tf.uint8, name=\"to_uint8\")\n",
" return output\n",
"\n",
"tf.reset_default_graph()\n",
"gray_graph = to_gray(coffee_cup)\n",
"#gray_graph = to_gray(coffee_cup)\n",
"\n",
"I = np.uint8(color.rgb2gray(coffee_cup)*255)\n",
"\n",
"with tf.Session() as sess:\n",
" gray_image = np.squeeze(sess.run(gray_graph))\n",
"# print gray_image.shape\n",
"# print I.shape\n",
"# print np.max(gray_image),np.min(gray_image),np.mean(gray_image)\n",
"# print np.max(I),np.min(I),np.mean(I)\n",
"# print np.max(np.abs(gray_image-I))\n",
" plt.imshow(np.squeeze(gray_image),'gray')\n",
" plt.show()\n",
"dot=tf_to_dot(tf.get_default_graph())\n",
"\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0 0]\n",
" [ 0 1]\n",
" [ 0 2]\n",
" ..., \n",
" [327 397]\n",
" [327 398]\n",
" [327 399]] [[ True True True ..., True True True]\n",
" [ True True True ..., True True True]\n",
" [ True True True ..., True True True]\n",
" ..., \n",
" [ True True True ..., True True True]\n",
" [ True True True ..., True True True]\n",
" [ True True True ..., True True True]]\n"
]
}
],
"source": [
"%matplotlib inline\n",
"import tensorflow as tf\n",
"import skimage.data as imgdata\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"horse = imgdata.horse().astype(np.uint8)\n",
"\n",
"def horse_color(img):\n",
"# horse_idx = tf.constant(img.)\n",
" horse = tf.constant(img.astype(bool),name='horse')\n",
"# white = tf.constant(np.ones((img.shape[0],img.shape[1],3),dtype=np.float64)*255)\n",
"# color = tf.constant(np.full((img.shape[0],img.shape[1],3),np.array([127.0,255.0,128.0]),dtype=np.float64))\n",
"# white = tf.constant(np.zeros(img.shape,dtype=np.uint8))\n",
"# color = tf.constant(np.ones(img.shape,dtype=np.uint8)*128)\n",
" horse_idx = tf.where(horse)\n",
"# colored_horse = tf.boolean_mask(color,horse)\n",
"# zero = tf.constant(0, dtype=tf.uint8)\n",
"# non_empty = tf.not_equal(horse, zero,name='horse_nonempty')\n",
"# unit8_nonempty_horse = tf.cast(tf.not_equal(horse, zero,name='horse_nonempty'),dtype=tf.uint8,name=\"to_uint8\")\n",
" return horse_idx\n",
"\n",
"tf.reset_default_graph()\n",
"horse_data = imgdata.horse()\n",
"horse_graph = horse_color(horse_data)\n",
"\n",
"with tf.Session() as sess:\n",
" horse_image = sess.run(horse_graph)\n",
" print horse_image,horse_data\n",
"# plt.imshow(horse_image)\n",
"# plt.show()\n",
"# dot=tf_to_dot(tf.get_default_graph())\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"980pt\" viewBox=\"0.00 0.00 1130.59 980.00\" width=\"1131pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 976)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"#ffffff\" points=\"-4,4 -4,-976 1126.5859,-976 1126.5859,4 -4,4\" stroke=\"transparent\"/>\n",
"<!-- train_data -->\n",
"<g class=\"node\" id=\"node1\">\n",
"<title>train_data</title>\n",
"<ellipse cx=\"703.8426\" cy=\"-954\" fill=\"none\" rx=\"58.4896\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"703.8426\" y=\"-950.3\">train_data</text>\n",
"</g>\n",
"<!-- div -->\n",
"<g class=\"node\" id=\"node3\">\n",
"<title>div</title>\n",
"<ellipse cx=\"703.8426\" cy=\"-882\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"703.8426\" y=\"-878.3\">div</text>\n",
"</g>\n",
"<!-- train_data&#45;&gt;div -->\n",
"<g class=\"edge\" id=\"edge1\">\n",
"<title>train_data-&gt;div</title>\n",
"<path d=\"M703.8426,-935.8314C703.8426,-928.131 703.8426,-918.9743 703.8426,-910.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"707.3427,-910.4132 703.8426,-900.4133 700.3427,-910.4133 707.3427,-910.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- train_label -->\n",
"<g class=\"node\" id=\"node2\">\n",
"<title>train_label</title>\n",
"<ellipse cx=\"688.8426\" cy=\"-450\" fill=\"none\" rx=\"60.3893\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"688.8426\" y=\"-446.3\">train_label</text>\n",
"</g>\n",
"<!-- mul -->\n",
"<g class=\"node\" id=\"node14\">\n",
"<title>mul</title>\n",
"<ellipse cx=\"472.8426\" cy=\"-306\" fill=\"none\" rx=\"28.6953\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"472.8426\" y=\"-302.3\">mul</text>\n",
"</g>\n",
"<!-- train_label&#45;&gt;mul -->\n",
"<g class=\"edge\" id=\"edge11\">\n",
"<title>train_label-&gt;mul</title>\n",
"<path d=\"M635.0363,-441.5459C583.9994,-432.4393 512.3017,-416.4607 492.8426,-396 477.2997,-379.6571 472.8078,-354.0389 471.9104,-334.3071\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"475.4055,-333.9852 471.7343,-324.0468 468.4065,-334.1054 475.4055,-333.9852\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- sub_1 -->\n",
"<g class=\"node\" id=\"node15\">\n",
"<title>sub_1</title>\n",
"<ellipse cx=\"671.8426\" cy=\"-378\" fill=\"none\" rx=\"38.1938\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"671.8426\" y=\"-374.3\">sub_1</text>\n",
"</g>\n",
"<!-- train_label&#45;&gt;sub_1 -->\n",
"<g class=\"edge\" id=\"edge13\">\n",
"<title>train_label-&gt;sub_1</title>\n",
"<path d=\"M684.5527,-431.8314C682.6863,-423.9266 680.4576,-414.4872 678.3915,-405.7365\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"681.7765,-404.8415 676.0721,-395.9134 674.9638,-406.4501 681.7765,-404.8415\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- gradients -->\n",
"<g class=\"node\" id=\"node23\">\n",
"<title>gradients</title>\n",
"<ellipse cx=\"502.8426\" cy=\"-162\" fill=\"none\" rx=\"55.4913\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"502.8426\" y=\"-158.3\">gradients</text>\n",
"</g>\n",
"<!-- train_label&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge27\">\n",
"<title>train_label-&gt;gradients</title>\n",
"<path d=\"M693.9076,-432.0027C699.3639,-421.9451 706.5067,-408.8733 709.8426,-396 726.1797,-332.9531 675.4338,-223.7224 667.8426,-216 651.985,-199.8686 599.5296,-184.9059 557.8924,-174.8417\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"558.6497,-171.4242 548.1114,-172.5176 557.0314,-178.2346 558.6497,-171.4242\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- train_label&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge30\">\n",
"<title>train_label-&gt;gradients</title>\n",
"<path d=\"M709.135,-432.9665C716.8991,-422.7886 724.3991,-409.2886 727.8426,-396 744.1797,-332.9531 693.4338,-223.7224 685.8426,-216 668.6969,-198.5581 608.7657,-182.4826 562.0165,-172.488\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"562.4651,-169.0063 551.9608,-170.388 561.0341,-175.8584 562.4651,-169.0063\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- sub -->\n",
"<g class=\"node\" id=\"node4\">\n",
"<title>sub</title>\n",
"<ellipse cx=\"703.8426\" cy=\"-810\" fill=\"none\" rx=\"27.0966\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"703.8426\" y=\"-806.3\">sub</text>\n",
"</g>\n",
"<!-- div&#45;&gt;sub -->\n",
"<g class=\"edge\" id=\"edge2\">\n",
"<title>div-&gt;sub</title>\n",
"<path d=\"M703.8426,-863.8314C703.8426,-856.131 703.8426,-846.9743 703.8426,-838.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"707.3427,-838.4132 703.8426,-828.4133 700.3427,-838.4133 707.3427,-838.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- MatMul -->\n",
"<g class=\"node\" id=\"node9\">\n",
"<title>MatMul</title>\n",
"<ellipse cx=\"411.8426\" cy=\"-738\" fill=\"none\" rx=\"47.3916\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"411.8426\" y=\"-734.3\">MatMul</text>\n",
"</g>\n",
"<!-- sub&#45;&gt;MatMul -->\n",
"<g class=\"edge\" id=\"edge4\">\n",
"<title>sub-&gt;MatMul</title>\n",
"<path d=\"M678.1854,-803.6736C629.9364,-791.7766 524.9051,-765.8784 462.1149,-750.3959\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"462.5853,-746.9071 452.0381,-747.9112 460.9094,-753.7036 462.5853,-746.9071\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- sub&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge44\">\n",
"<title>sub-&gt;gradients</title>\n",
"<path d=\"M730.4116,-804.6995C757.4295,-797.9495 798.6596,-783.6768 822.8426,-756 850.3205,-724.5522 849.8426,-707.7612 849.8426,-666 849.8426,-666 849.8426,-666 849.8426,-306 849.8426,-251.2846 813.5634,-242.7675 765.8426,-216 731.9593,-196.9942 630.6928,-179.8441 564.1616,-170.1912\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"564.5992,-166.7182 554.2039,-168.7647 563.6065,-173.6475 564.5992,-166.7182\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Const -->\n",
"<g class=\"node\" id=\"node5\">\n",
"<title>Const</title>\n",
"<ellipse cx=\"915.8426\" cy=\"-234\" fill=\"none\" rx=\"38.1938\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"915.8426\" y=\"-230.3\">Const</text>\n",
"</g>\n",
"<!-- Neg_1 -->\n",
"<g class=\"node\" id=\"node25\">\n",
"<title>Neg_1</title>\n",
"<ellipse cx=\"716.8426\" cy=\"-162\" fill=\"none\" rx=\"40.8928\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"716.8426\" y=\"-158.3\">Neg_1</text>\n",
"</g>\n",
"<!-- Const&#45;&gt;Neg_1 -->\n",
"<g class=\"edge\" id=\"edge45\">\n",
"<title>Const-&gt;Neg_1</title>\n",
"<path d=\"M885.1849,-222.9078C851.157,-210.5962 796.0594,-190.6614 758.2245,-176.9724\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"759.1167,-173.5732 748.5225,-173.4621 756.7351,-180.1556 759.1167,-173.5732\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Neg_2 -->\n",
"<g class=\"node\" id=\"node28\">\n",
"<title>Neg_2</title>\n",
"<ellipse cx=\"915.8426\" cy=\"-162\" fill=\"none\" rx=\"40.8928\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"915.8426\" y=\"-158.3\">Neg_2</text>\n",
"</g>\n",
"<!-- Const&#45;&gt;Neg_2 -->\n",
"<g class=\"edge\" id=\"edge50\">\n",
"<title>Const-&gt;Neg_2</title>\n",
"<path d=\"M915.8426,-215.8314C915.8426,-208.131 915.8426,-198.9743 915.8426,-190.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"919.3427,-190.4132 915.8426,-180.4133 912.3427,-190.4133 919.3427,-190.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- random_normal -->\n",
"<g class=\"node\" id=\"node6\">\n",
"<title>random_normal</title>\n",
"<ellipse cx=\"83.8426\" cy=\"-882\" fill=\"none\" rx=\"83.6854\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"83.8426\" y=\"-878.3\">random_normal</text>\n",
"</g>\n",
"<!-- weights -->\n",
"<g class=\"node\" id=\"node7\">\n",
"<title>weights</title>\n",
"<ellipse cx=\"83.8426\" cy=\"-810\" fill=\"none\" rx=\"47.3916\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"83.8426\" y=\"-806.3\">weights</text>\n",
"</g>\n",
"<!-- random_normal&#45;&gt;weights -->\n",
"<g class=\"edge\" id=\"edge3\">\n",
"<title>random_normal-&gt;weights</title>\n",
"<path d=\"M83.8426,-863.8314C83.8426,-856.131 83.8426,-846.9743 83.8426,-838.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"87.3427,-838.4132 83.8426,-828.4133 80.3427,-838.4133 87.3427,-838.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- weights&#45;&gt;MatMul -->\n",
"<g class=\"edge\" id=\"edge5\">\n",
"<title>weights-&gt;MatMul</title>\n",
"<path d=\"M125.0519,-800.9541C184.8275,-787.8326 295.5268,-763.5327 360.5201,-749.2659\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"361.5268,-752.6283 370.5438,-747.0656 360.0259,-745.7911 361.5268,-752.6283\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- weights&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge43\">\n",
"<title>weights-&gt;gradients</title>\n",
"<path d=\"M83.8426,-791.8146C83.8426,-764.4983 83.8426,-711.25 83.8426,-666 83.8426,-666 83.8426,-666 83.8426,-306 83.8426,-265.1184 72.8872,-243.8205 102.8426,-216 126.9982,-193.5659 331.7766,-174.9351 438.5822,-166.6382\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"438.9008,-170.1241 448.6031,-165.8677 438.3642,-163.1447 438.9008,-170.1241\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- weight_update -->\n",
"<g class=\"node\" id=\"node27\">\n",
"<title>weight_update</title>\n",
"<ellipse cx=\"274.8426\" cy=\"-18\" fill=\"none\" rx=\"79.0865\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"274.8426\" y=\"-14.3\">weight_update</text>\n",
"</g>\n",
"<!-- weights&#45;&gt;weight_update -->\n",
"<g class=\"edge\" id=\"edge48\">\n",
"<title>weights-&gt;weight_update</title>\n",
"<path d=\"M75.9689,-792.2135C64.8385,-765.4059 45.8426,-712.799 45.8426,-666 45.8426,-666 45.8426,-666 45.8426,-162 45.8426,-86.5751 135.9696,-49.1121 203.1413,-31.6649\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"204.0184,-35.0534 212.8719,-29.2339 202.3217,-28.2622 204.0184,-35.0534\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Variable -->\n",
"<g class=\"node\" id=\"node8\">\n",
"<title>Variable</title>\n",
"<ellipse cx=\"764.8426\" cy=\"-738\" fill=\"none\" rx=\"48.9926\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"764.8426\" y=\"-734.3\">Variable</text>\n",
"</g>\n",
"<!-- add -->\n",
"<g class=\"node\" id=\"node10\">\n",
"<title>add</title>\n",
"<ellipse cx=\"755.8426\" cy=\"-666\" fill=\"none\" rx=\"27.8951\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"755.8426\" y=\"-662.3\">add</text>\n",
"</g>\n",
"<!-- Variable&#45;&gt;add -->\n",
"<g class=\"edge\" id=\"edge7\">\n",
"<title>Variable-&gt;add</title>\n",
"<path d=\"M762.5715,-719.8314C761.6089,-712.131 760.4644,-702.9743 759.3946,-694.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"762.8576,-693.9019 758.1442,-684.4133 755.9117,-694.7702 762.8576,-693.9019\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- bias_update -->\n",
"<g class=\"node\" id=\"node30\">\n",
"<title>bias_update</title>\n",
"<ellipse cx=\"1006.8426\" cy=\"-18\" fill=\"none\" rx=\"66.8882\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"1006.8426\" y=\"-14.3\">bias_update</text>\n",
"</g>\n",
"<!-- Variable&#45;&gt;bias_update -->\n",
"<g class=\"edge\" id=\"edge53\">\n",
"<title>Variable-&gt;bias_update</title>\n",
"<path d=\"M781.3343,-720.9477C836.9584,-662.0871 1017.6022,-459.6344 1078.8426,-252 1093.1992,-203.324 1080.8068,-123.993 1055.8426,-72 1050.7244,-61.3404 1042.8179,-51.2706 1034.8391,-42.7792\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"1037.0974,-40.0861 1027.5692,-35.4532 1032.1286,-45.0168 1037.0974,-40.0861\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- MatMul&#45;&gt;add -->\n",
"<g class=\"edge\" id=\"edge6\">\n",
"<title>MatMul-&gt;add</title>\n",
"<path d=\"M453.6798,-729.2434C521.5252,-715.0432 654.4397,-687.2239 718.9571,-673.7202\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"720.0023,-677.0774 729.0732,-671.6029 718.5682,-670.2258 720.0023,-677.0774\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- MatMul&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge42\">\n",
"<title>MatMul-&gt;gradients</title>\n",
"<path d=\"M380.5219,-724.2282C337.6223,-702.9897 265.8426,-657.9051 265.8426,-594 265.8426,-594 265.8426,-594 265.8426,-306 265.8426,-223.4005 372.2846,-186.8381 442.501,-171.7051\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"443.4947,-175.0739 452.581,-169.625 442.0799,-168.2184 443.4947,-175.0739\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Sigmoid -->\n",
"<g class=\"node\" id=\"node11\">\n",
"<title>Sigmoid</title>\n",
"<ellipse cx=\"764.8426\" cy=\"-594\" fill=\"none\" rx=\"48.9926\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"764.8426\" y=\"-590.3\">Sigmoid</text>\n",
"</g>\n",
"<!-- add&#45;&gt;Sigmoid -->\n",
"<g class=\"edge\" id=\"edge8\">\n",
"<title>add-&gt;Sigmoid</title>\n",
"<path d=\"M758.1136,-647.8314C759.0762,-640.131 760.2208,-630.9743 761.2905,-622.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"764.7734,-622.7702 762.5409,-612.4133 757.8275,-621.9019 764.7734,-622.7702\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- add_1 -->\n",
"<g class=\"node\" id=\"node12\">\n",
"<title>add_1</title>\n",
"<ellipse cx=\"373.8426\" cy=\"-522\" fill=\"none\" rx=\"38.1938\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"373.8426\" y=\"-518.3\">add_1</text>\n",
"</g>\n",
"<!-- Sigmoid&#45;&gt;add_1 -->\n",
"<g class=\"edge\" id=\"edge9\">\n",
"<title>Sigmoid-&gt;add_1</title>\n",
"<path d=\"M721.128,-585.9503C646.7107,-572.2468 496.1011,-544.5131 420.0316,-530.5054\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"420.2767,-526.9918 409.8082,-528.6228 419.009,-533.876 420.2767,-526.9918\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Sigmoid&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge40\">\n",
"<title>Sigmoid-&gt;gradients</title>\n",
"<path d=\"M767.0299,-575.7668C775.0559,-548.8248 793.8426,-496.5405 793.8426,-450 793.8426,-450 793.8426,-450 793.8426,-306 793.8426,-248.1607 750.3211,-244.2366 699.8426,-216 657.4543,-192.2889 604.3242,-178.693 563.8547,-171.0748\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"564.3164,-167.6016 553.8529,-169.2643 563.0695,-174.4897 564.3164,-167.6016\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Sigmoid&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge41\">\n",
"<title>Sigmoid-&gt;gradients</title>\n",
"<path d=\"M778.2985,-576.6554C792.6361,-549.9874 811.8426,-497.0576 811.8426,-450 811.8426,-450 811.8426,-450 811.8426,-306 811.8426,-248.1607 768.3211,-244.2366 717.8426,-216 670.8953,-189.7387 610.7713,-175.8855 565.9609,-168.819\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"566.4786,-165.3576 556.0689,-167.3298 565.4364,-172.2796 566.4786,-165.3576\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log -->\n",
"<g class=\"node\" id=\"node13\">\n",
"<title>Log</title>\n",
"<ellipse cx=\"378.8426\" cy=\"-378\" fill=\"none\" rx=\"28.6953\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"378.8426\" y=\"-374.3\">Log</text>\n",
"</g>\n",
"<!-- add_1&#45;&gt;Log -->\n",
"<g class=\"edge\" id=\"edge10\">\n",
"<title>add_1-&gt;Log</title>\n",
"<path d=\"M374.4758,-503.7623C375.3286,-479.201 376.8548,-435.2474 377.858,-406.3541\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"381.3652,-406.2051 378.2144,-396.0896 374.3694,-405.9621 381.3652,-406.2051\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- sub_2 -->\n",
"<g class=\"node\" id=\"node16\">\n",
"<title>sub_2</title>\n",
"<ellipse cx=\"439.8426\" cy=\"-450\" fill=\"none\" rx=\"38.1938\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"439.8426\" y=\"-446.3\">sub_2</text>\n",
"</g>\n",
"<!-- add_1&#45;&gt;sub_2 -->\n",
"<g class=\"edge\" id=\"edge14\">\n",
"<title>add_1-&gt;sub_2</title>\n",
"<path d=\"M389.1502,-505.3008C397.6468,-496.0317 408.3651,-484.339 417.7551,-474.0954\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"420.4407,-476.3453 424.618,-466.6087 415.2806,-471.6152 420.4407,-476.3453\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- add_1&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge35\">\n",
"<title>add_1-&gt;gradients</title>\n",
"<path d=\"M356.0785,-505.6706C335.0137,-479.9205 303.8426,-427.6856 303.8426,-378 303.8426,-378 303.8426,-378 303.8426,-306 303.8426,-235.0357 389.069,-194.5349 448.0655,-175.5237\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"449.1426,-178.8542 457.6554,-172.5469 447.0673,-172.1689 449.1426,-178.8542\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- add_1&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge39\">\n",
"<title>add_1-&gt;gradients</title>\n",
"<path d=\"M366.5298,-503.9445C351.6659,-477.6382 321.8426,-426.5995 321.8426,-378 321.8426,-378 321.8426,-378 321.8426,-306 321.8426,-238.2022 399.633,-198.2099 453.3058,-178.1977\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"454.8046,-181.3779 463.0229,-174.6914 452.4285,-174.7935 454.8046,-181.3779\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log&#45;&gt;mul -->\n",
"<g class=\"edge\" id=\"edge12\">\n",
"<title>Log-&gt;mul</title>\n",
"<path d=\"M397.4139,-363.7751C411.4088,-353.0557 430.7902,-338.2103 446.4022,-326.2522\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"448.8191,-328.8097 454.6296,-319.9503 444.5625,-323.2526 448.8191,-328.8097\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge28\">\n",
"<title>Log-&gt;gradients</title>\n",
"<path d=\"M371.2607,-360.5705C364.2459,-328.755 361.7415,-260.4589 392.8426,-216 405.9386,-197.2793 427.6256,-184.4851 448.3672,-176.0687\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"449.68,-179.3143 457.7963,-172.5043 447.2048,-172.7665 449.68,-179.3143\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge29\">\n",
"<title>Log-&gt;gradients</title>\n",
"<path d=\"M381.7919,-360.0678C382.2206,-328.0405 379.9043,-260.2261 410.8426,-216 422.0941,-199.916 439.687,-188.2067 456.5413,-179.8899\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"458.1788,-182.9887 465.7838,-175.6122 455.2386,-176.6361 458.1788,-182.9887\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- add_2 -->\n",
"<g class=\"node\" id=\"node19\">\n",
"<title>add_2</title>\n",
"<ellipse cx=\"577.8426\" cy=\"-234\" fill=\"none\" rx=\"38.1938\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"577.8426\" y=\"-230.3\">add_2</text>\n",
"</g>\n",
"<!-- mul&#45;&gt;add_2 -->\n",
"<g class=\"edge\" id=\"edge18\">\n",
"<title>mul-&gt;add_2</title>\n",
"<path d=\"M492.5923,-292.4574C508.1121,-281.8152 529.9895,-266.8135 547.6958,-254.6721\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"549.7389,-257.515 556.0068,-248.9731 545.7801,-251.7419 549.7389,-257.515\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge25\">\n",
"<title>mul-&gt;gradients</title>\n",
"<path d=\"M472.5414,-287.7986C472.6353,-269.4232 473.8787,-240.356 479.8426,-216 482.0374,-207.0365 485.5577,-197.657 489.191,-189.2775\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"492.4643,-190.5352 493.4354,-179.985 486.097,-187.6269 492.4643,-190.5352\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_1 -->\n",
"<g class=\"node\" id=\"node18\">\n",
"<title>mul_1</title>\n",
"<ellipse cx=\"614.8426\" cy=\"-306\" fill=\"none\" rx=\"38.9931\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"614.8426\" y=\"-302.3\">mul_1</text>\n",
"</g>\n",
"<!-- sub_1&#45;&gt;mul_1 -->\n",
"<g class=\"edge\" id=\"edge16\">\n",
"<title>sub_1-&gt;mul_1</title>\n",
"<path d=\"M658.3344,-360.937C651.2357,-351.9703 642.4024,-340.8124 634.5545,-330.8993\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"637.205,-328.6085 628.2538,-322.9405 631.7167,-332.9535 637.205,-328.6085\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- sub_1&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge31\">\n",
"<title>sub_1-&gt;gradients</title>\n",
"<path d=\"M669.0162,-360.0479C668.5962,-327.071 670.6074,-256.5233 633.8426,-216 614.596,-194.7859 586.0561,-181.8333 560.4694,-173.9589\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"561.4113,-170.588 550.8332,-171.183 559.4736,-177.3145 561.4113,-170.588\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- sub_1&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge34\">\n",
"<title>sub_1-&gt;gradients</title>\n",
"<path d=\"M679.4258,-360.3055C686.5855,-327.4396 688.7033,-256.6291 651.8426,-216 629.6682,-191.5587 595.1578,-178.0836 564.8594,-170.7066\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"565.2947,-167.217 554.7697,-168.4316 563.7549,-174.0455 565.2947,-167.217\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log_1 -->\n",
"<g class=\"node\" id=\"node17\">\n",
"<title>Log_1</title>\n",
"<ellipse cx=\"540.8426\" cy=\"-378\" fill=\"none\" rx=\"38.9931\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"540.8426\" y=\"-374.3\">Log_1</text>\n",
"</g>\n",
"<!-- sub_2&#45;&gt;Log_1 -->\n",
"<g class=\"edge\" id=\"edge15\">\n",
"<title>sub_2-&gt;Log_1</title>\n",
"<path d=\"M461.2621,-434.7307C475.724,-424.4212 495.0126,-410.6709 510.9779,-399.2896\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"513.3428,-401.9021 519.4539,-393.2473 509.2795,-396.2022 513.3428,-401.9021\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- sub_2&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge37\">\n",
"<title>sub_2-&gt;gradients</title>\n",
"<path d=\"M436.2283,-431.7122C430.906,-401.375 422.8179,-338.9373 434.8426,-288 443.6929,-250.5094 466.7464,-212.2364 483.5643,-187.8665\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"486.5315,-189.732 489.4403,-179.5443 480.8133,-185.6945 486.5315,-189.732\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log_1&#45;&gt;mul_1 -->\n",
"<g class=\"edge\" id=\"edge17\">\n",
"<title>Log_1-&gt;mul_1</title>\n",
"<path d=\"M557.6343,-361.6621C567.4741,-352.0882 580.0646,-339.8381 590.9277,-329.2686\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"593.3907,-331.7554 598.1173,-322.2733 588.5092,-326.7383 593.3907,-331.7554\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log_1&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge32\">\n",
"<title>Log_1-&gt;gradients</title>\n",
"<path d=\"M533.7222,-359.9555C523.6417,-322.3144 508.0543,-235.1867 503.0665,-190.1246\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"506.5469,-189.752 502.0796,-180.1451 499.5808,-190.441 506.5469,-189.752\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Log_1&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge33\">\n",
"<title>Log_1-&gt;gradients</title>\n",
"<path d=\"M541.614,-359.9555C538.4437,-322.235 523.318,-234.8188 512.4455,-189.8399\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"515.8382,-188.9795 509.9899,-180.1451 509.0525,-190.6984 515.8382,-188.9795\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_1&#45;&gt;add_2 -->\n",
"<g class=\"edge\" id=\"edge19\">\n",
"<title>mul_1-&gt;add_2</title>\n",
"<path d=\"M605.6965,-288.2022C601.4399,-279.9192 596.2868,-269.8915 591.5761,-260.7248\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"594.5672,-258.8876 586.8834,-251.593 588.3412,-262.0871 594.5672,-258.8876\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_1&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge26\">\n",
"<title>mul_1-&gt;gradients</title>\n",
"<path d=\"M623.0995,-288.2092C630.7492,-268.8434 638.9941,-237.7396 624.8426,-216 610.6821,-194.2467 585.542,-181.1908 561.7479,-173.386\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"562.6067,-169.9893 552.0218,-170.4501 560.5837,-176.6907 562.6067,-169.9893\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Mean -->\n",
"<g class=\"node\" id=\"node21\">\n",
"<title>Mean</title>\n",
"<ellipse cx=\"1015.8426\" cy=\"-162\" fill=\"none\" rx=\"36.2938\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"1015.8426\" y=\"-158.3\">Mean</text>\n",
"</g>\n",
"<!-- add_2&#45;&gt;Mean -->\n",
"<g class=\"edge\" id=\"edge20\">\n",
"<title>add_2-&gt;Mean</title>\n",
"<path d=\"M615.7898,-231.3427C685.8163,-225.8625 839.7255,-211.1199 965.8426,-180 969.7124,-179.0451 973.7001,-177.8999 977.6556,-176.6557\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"978.967,-179.9076 987.3366,-173.4114 976.7427,-173.2704 978.967,-179.9076\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- add_2&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge23\">\n",
"<title>add_2-&gt;gradients</title>\n",
"<path d=\"M556.301,-218.7307C545.636,-209.5628 532.9739,-197.674 522.5705,-187.1498\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"524.921,-184.5455 515.4553,-179.7862 519.8871,-189.4096 524.921,-184.5455\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- add_2&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge24\">\n",
"<title>add_2-&gt;gradients</title>\n",
"<path d=\"M565.5654,-216.5708C556.743,-207.1703 544.688,-195.4433 533.4444,-185.2721\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"535.6434,-182.5441 525.8397,-178.5267 530.9984,-187.7809 535.6434,-182.5441\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Const_1 -->\n",
"<g class=\"node\" id=\"node20\">\n",
"<title>Const_1</title>\n",
"<ellipse cx=\"1020.8426\" cy=\"-234\" fill=\"none\" rx=\"48.9926\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"1020.8426\" y=\"-230.3\">Const_1</text>\n",
"</g>\n",
"<!-- Const_1&#45;&gt;Mean -->\n",
"<g class=\"edge\" id=\"edge21\">\n",
"<title>Const_1-&gt;Mean</title>\n",
"<path d=\"M1019.5808,-215.8314C1019.0461,-208.131 1018.4102,-198.9743 1017.8159,-190.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"1021.3057,-190.1467 1017.1213,-180.4133 1014.3225,-190.6317 1021.3057,-190.1467\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Neg -->\n",
"<g class=\"node\" id=\"node22\">\n",
"<title>Neg</title>\n",
"<ellipse cx=\"1015.8426\" cy=\"-90\" fill=\"none\" rx=\"30.5947\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"1015.8426\" y=\"-86.3\">Neg</text>\n",
"</g>\n",
"<!-- Mean&#45;&gt;Neg -->\n",
"<g class=\"edge\" id=\"edge22\">\n",
"<title>Mean-&gt;Neg</title>\n",
"<path d=\"M1015.8426,-143.8314C1015.8426,-136.131 1015.8426,-126.9743 1015.8426,-118.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"1019.3427,-118.4132 1015.8426,-108.4133 1012.3427,-118.4133 1019.3427,-118.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_2 -->\n",
"<g class=\"node\" id=\"node26\">\n",
"<title>mul_2</title>\n",
"<ellipse cx=\"502.8426\" cy=\"-90\" fill=\"none\" rx=\"38.9931\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"502.8426\" y=\"-86.3\">mul_2</text>\n",
"</g>\n",
"<!-- gradients&#45;&gt;mul_2 -->\n",
"<g class=\"edge\" id=\"edge47\">\n",
"<title>gradients-&gt;mul_2</title>\n",
"<path d=\"M502.8426,-143.8314C502.8426,-136.131 502.8426,-126.9743 502.8426,-118.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"506.3427,-118.4132 502.8426,-108.4133 499.3427,-118.4133 506.3427,-118.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_3 -->\n",
"<g class=\"node\" id=\"node29\">\n",
"<title>mul_3</title>\n",
"<ellipse cx=\"915.8426\" cy=\"-90\" fill=\"none\" rx=\"38.9931\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"915.8426\" y=\"-86.3\">mul_3</text>\n",
"</g>\n",
"<!-- gradients&#45;&gt;mul_3 -->\n",
"<g class=\"edge\" id=\"edge52\">\n",
"<title>gradients-&gt;mul_3</title>\n",
"<path d=\"M551.8409,-153.4579C632.1031,-139.4655 790.522,-111.8477 869.2146,-98.1288\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"870.0673,-101.5331 879.3176,-96.3676 868.865,-94.6371 870.0673,-101.5331\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- ^gradients -->\n",
"<g class=\"node\" id=\"node24\">\n",
"<title>^gradients</title>\n",
"<ellipse cx=\"174.8426\" cy=\"-234\" fill=\"none\" rx=\"63.0888\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"174.8426\" y=\"-230.3\">^gradients</text>\n",
"</g>\n",
"<!-- ^gradients&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge36\">\n",
"<title>^gradients-&gt;gradients</title>\n",
"<path d=\"M219.7597,-221.2898C227.4372,-219.4919 235.3412,-217.6836 242.8426,-216 311.6888,-200.5486 391.3646,-183.5586 444.281,-172.8408\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"445.0569,-176.2549 454.1687,-170.8488 443.6744,-169.3928 445.0569,-176.2549\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- ^gradients&#45;&gt;gradients -->\n",
"<g class=\"edge\" id=\"edge38\">\n",
"<title>^gradients-&gt;gradients</title>\n",
"<path d=\"M227.0987,-223.6796C238.2997,-221.1313 249.9924,-218.4351 260.8426,-216 325.3337,-201.526 399.3276,-185.702 448.4289,-174.9481\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"449.195,-178.3634 458.2115,-172.7998 447.6935,-171.5263 449.195,-178.3634\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Neg_1&#45;&gt;mul_2 -->\n",
"<g class=\"edge\" id=\"edge46\">\n",
"<title>Neg_1-&gt;mul_2</title>\n",
"<path d=\"M683.874,-150.9078C646.2895,-138.2625 584.8022,-117.5752 544.0774,-103.8734\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"545.0463,-100.5067 534.4523,-100.635 542.8141,-107.1412 545.0463,-100.5067\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_2&#45;&gt;weight_update -->\n",
"<g class=\"edge\" id=\"edge49\">\n",
"<title>mul_2-&gt;weight_update</title>\n",
"<path d=\"M470.1757,-79.6842C433.8871,-68.2246 374.656,-49.52 330.9173,-35.7078\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"331.8657,-32.337 321.2759,-32.6632 329.7578,-39.0121 331.8657,-32.337\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- Neg_2&#45;&gt;mul_3 -->\n",
"<g class=\"edge\" id=\"edge51\">\n",
"<title>Neg_2-&gt;mul_3</title>\n",
"<path d=\"M915.8426,-143.8314C915.8426,-136.131 915.8426,-126.9743 915.8426,-118.4166\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"919.3427,-118.4132 915.8426,-108.4133 912.3427,-118.4133 919.3427,-118.4132\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- mul_3&#45;&gt;bias_update -->\n",
"<g class=\"edge\" id=\"edge54\">\n",
"<title>mul_3-&gt;bias_update</title>\n",
"<path d=\"M935.5882,-74.3771C947.709,-64.787 963.4656,-52.3202 977.0788,-41.5493\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"979.5558,-44.0526 985.2264,-35.1029 975.2124,-38.563 979.5558,-44.0526\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- NoOp -->\n",
"<g class=\"node\" id=\"node31\">\n",
"<title>NoOp</title>\n",
"<ellipse cx=\"957.8426\" cy=\"-882\" fill=\"none\" rx=\"38.1938\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"957.8426\" y=\"-878.3\">NoOp</text>\n",
"</g>\n",
"<!-- ^weight_update -->\n",
"<g class=\"node\" id=\"node32\">\n",
"<title>^weight_update</title>\n",
"<ellipse cx=\"867.8426\" cy=\"-954\" fill=\"none\" rx=\"87.1846\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"867.8426\" y=\"-950.3\">^weight_update</text>\n",
"</g>\n",
"<!-- ^weight_update&#45;&gt;NoOp -->\n",
"<g class=\"edge\" id=\"edge55\">\n",
"<title>^weight_update-&gt;NoOp</title>\n",
"<path d=\"M889.6291,-936.5708C901.9504,-926.7138 917.469,-914.2988 930.5904,-903.8017\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"932.7782,-906.5337 938.4005,-897.5537 928.4053,-901.0676 932.7782,-906.5337\" stroke=\"#000000\"/>\n",
"</g>\n",
"<!-- ^bias_update -->\n",
"<g class=\"node\" id=\"node33\">\n",
"<title>^bias_update</title>\n",
"<ellipse cx=\"1047.8426\" cy=\"-954\" fill=\"none\" rx=\"74.9875\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"1047.8426\" y=\"-950.3\">^bias_update</text>\n",
"</g>\n",
"<!-- ^bias_update&#45;&gt;NoOp -->\n",
"<g class=\"edge\" id=\"edge56\">\n",
"<title>^bias_update-&gt;NoOp</title>\n",
"<path d=\"M1026.0561,-936.5708C1013.7348,-926.7138 998.2161,-914.2988 985.0947,-903.8017\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"987.2798,-901.0676 977.2846,-897.5537 982.9069,-906.5337 987.2798,-901.0676\" stroke=\"#000000\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training loss after 0 iterations: 0.693686\n",
"Training loss after 100 iterations: 0.342306\n",
"Training loss after 200 iterations: 0.210373\n",
"Training loss after 300 iterations: 0.174988\n",
"Training loss after 400 iterations: 0.152505\n",
"Training loss after 500 iterations: 0.136287\n",
"Training loss after 600 iterations: 0.123976\n",
"Training loss after 700 iterations: 0.114264\n",
"Training loss after 800 iterations: 0.106370\n",
"Training loss after 900 iterations: 0.099801\n",
"Training loss after 1000 iterations: 0.094227\n",
"Training loss after 1100 iterations: 0.089424\n",
"Training loss after 1200 iterations: 0.085229\n",
"Training loss after 1300 iterations: 0.081525\n",
"Training loss after 1400 iterations: 0.078224\n",
"Training loss after 1500 iterations: 0.075257\n",
"Training loss after 1600 iterations: 0.072572\n",
"Training loss after 1700 iterations: 0.070125\n",
"Training loss after 1800 iterations: 0.067885\n",
"Training loss after 1900 iterations: 0.065823\n",
"Accuracy of the model is 0.93\n"
]
}
],
"source": [
"%matplotlib inline\n",
"from graphviz import Digraph\n",
"from IPython.core.display import display, SVG\n",
"\n",
"def tf_to_dot(graph):\n",
" dot = Digraph()\n",
"\n",
" for n in graph.as_graph_def().node:\n",
" name = n.name.split('/')[0]\n",
" dot.node(name, label=name)\n",
"\n",
" for src in n.input:\n",
" src = src.split('/')[0]\n",
" if src != name:\n",
" dot.edge(src, name)\n",
" display(SVG(dot._repr_svg_()))\n",
" return dot\n",
"\n",
"import numpy as np\n",
"import scipy.io\n",
"import matplotlib.pyplot as plt\n",
"import tensorflow as tf\n",
"\n",
"mat = scipy.io.loadmat('./FaceNonFace.mat')\n",
"\n",
"faces = np.rollaxis(mat[\"face\"].astype(np.uint8),-1,0)\n",
"non_faces = np.rollaxis(mat[\"nonFace\"].astype(np.uint8),-1,0)\n",
"\n",
"rand_idx = np.arange(0,faces.shape[0])\n",
"np.random.shuffle(rand_idx)\n",
"\n",
"train_test_split = 0.8\n",
"\n",
"face_split = np.int(train_test_split*faces.shape[0])\n",
"\n",
"train_faces = faces[rand_idx[:face_split]]\n",
"test_faces = faces[rand_idx[face_split:]]\n",
"\n",
"non_face_split = np.int(train_test_split*non_faces.shape[0])\n",
"train_non_faces = non_faces[rand_idx[:non_face_split]]\n",
"test_non_faces = non_faces[rand_idx[non_face_split:]]\n",
"\n",
"train_data = np.vstack([train_faces,train_non_faces])\n",
"train_labels = np.array([0]*len(train_faces)+[1]*len(train_non_faces)).astype(np.float32).reshape(-1,1)\n",
"\n",
"test_data = np.vstack([test_faces,test_non_faces])\n",
"test_labels = np.array([0]*len(test_faces)+[1]*len(test_non_faces)).astype(np.float32).reshape(-1,1)\n",
"\n",
"train_data = train_data.reshape(train_data.shape[0],-1).astype(np.float32)\n",
"test_data = test_data.reshape(test_data.shape[0],-1).astype(np.float32)\n",
"\n",
"# plt.imshow((train_data[1000].reshape(60,60,3)*255).astype(np.float32))\n",
"# plt.show()\n",
"\n",
"# tf.reset_default_graph()\n",
"def build_graph():\n",
" g = tf.Graph()\n",
" with g.as_default():\n",
" train_x = tf.placeholder(shape=[None,train_data.shape[1]],name=\"train_data\",dtype=np.float32)\n",
" train_y = tf.placeholder(shape=[None,1],name=\"train_label\",dtype=np.float32)\n",
"\n",
"\n",
" train_x1 = tf.div(train_x,255.0)-0.5\n",
"\n",
" learning_rate = tf.constant(0.05)\n",
"\n",
" weights = tf.Variable(tf.random_normal([train_data.shape[1],1],stddev=1e-3),name=\"weights\")\n",
" bias = tf.Variable(0.1,dtype=np.float32)\n",
"\n",
" h = tf.matmul(train_x1,weights)+bias\n",
" z = tf.sigmoid(h)+1e-6\n",
"\n",
" loss = -tf.reduce_mean(train_y*tf.log(z) + (1-train_y)*tf.log(1-z))\n",
" dw,db = tf.gradients(loss,[weights,bias])\n",
"\n",
" weights_update = tf.assign_add(weights,-learning_rate*dw,name='weight_update')\n",
" bias_update = tf.assign_add(bias,-learning_rate*db,name='bias_update')\n",
"\n",
" with tf.control_dependencies([weights_update,bias_update]):\n",
" train_op = tf.no_op()\n",
" tf_to_dot(g)\n",
" return (g,loss,train_op,train_x,train_y,z)\n",
"\n",
"(g,loss,train_op,train_x,train_y,z) = build_graph()\n",
"\n",
"with g.as_default():\n",
" with tf.Session() as sess:\n",
" sess.run(tf.global_variables_initializer())\n",
" for i in xrange(2000):\n",
" l,_ = sess.run([loss,train_op],feed_dict={train_x:train_data,train_y:train_labels})\n",
" if i%100 == 0:\n",
" print 'Training loss after %d iterations: %f'%(i,l)\n",
"\n",
" y_ = sess.run(z,feed_dict = {train_x:test_data})\n",
" y_ = y_ > 0.5\n",
" accuracy = np.sum((y_ == (test_labels > 0)),0)[0]/(y_.shape[0]*1.0)\n",
" print 'Accuracy of the model is ',accuracy\n"
]
},
2017-10-08 09:42:12 +00:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
2017-10-08 09:42:12 +00:00
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 1
}