From 78e13cf1884a634078215825007df56114b0b640 Mon Sep 17 00:00:00 2001 From: Dylan Madisetti Date: Tue, 9 Mar 2021 18:10:52 -0500 Subject: [PATCH 1/2] Fix broken Graph View --- tf-graph/tf-graph-basic.build.html | 11 ++++++++++- tf-graph/tf-graph-basic.build.js | 2 +- tfutils.py | 30 ++++++++++-------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/tf-graph/tf-graph-basic.build.html b/tf-graph/tf-graph-basic.build.html index 786d07a..e860c58 100644 --- a/tf-graph/tf-graph-basic.build.html +++ b/tf-graph/tf-graph-basic.build.html @@ -1053,4 +1053,13 @@

[[title]]

- + +
+ +
+ + diff --git a/tf-graph/tf-graph-basic.build.js b/tf-graph/tf-graph-basic.build.js index b7168ae..43e0da9 100644 --- a/tf-graph/tf-graph-basic.build.js +++ b/tf-graph/tf-graph-basic.build.js @@ -38447,7 +38447,7 @@ return this.disabled || !this.required || this.required && this.value; Polymer({ is: 'tf-graph-controls', ready: function () { -d3.select(this.$['summary-icon']).attr('xlink:href', '/files/tf-graph/summary-icon.svg'); +d3.select(this.$['summary-icon']).attr('xlink:href', 'summary-icon.svg'); }, properties: { hasStats: { type: Boolean }, diff --git a/tfutils.py b/tfutils.py index a436495..b20cc2e 100644 --- a/tfutils.py +++ b/tfutils.py @@ -1,12 +1,13 @@ import tensorflow as tf import numpy as np +from base64 import b64encode from IPython.display import clear_output, Image, display, HTML def graph_as_HTML(graph_def, baseURL=''): # Helper functions for TF Graph visualization def _strip_consts(graph_def, max_const_size=32): """Strip large constant values from graph_def.""" - strip_def = tf.GraphDef() + strip_def = graph_pb2.GraphDef() for n0 in graph_def.node: n = strip_def.node.add() n.MergeFrom(n0) @@ -14,7 +15,7 @@ def _strip_consts(graph_def, max_const_size=32): tensor = n.attr['value'].tensor size = len(tensor.tensor_content) if size > max_const_size: - tensor.tensor_content = "".format(size).encode() + tensor.tensor_content = "" % size return strip_def def _rename_nodes(graph_def, rename_func): @@ -31,24 +32,13 @@ def _show_entire_graph(graph_def, max_const_size=32): """Visualize TensorFlow graph.""" if hasattr(graph_def, 'as_graph_def'): graph_def = graph_def.as_graph_def() - strip_def = _strip_consts(graph_def, max_const_size=max_const_size) - code = """ - - -
- -
- """.format(data=repr(str(strip_def)), id='graph' + str(np.random.rand()), baseURL=baseURL) - - iframe = """ - - """.format(code.replace('"', '"')) - - return iframe + strip_def = strip_consts(graph_def, max_const_size=max_const_size) + data = b64encode(str(strip_def).encode()).decode() + id = str(np.random.rand()) + page = "https://raw.githack.com/AnotherGroupChat/Machine-Learning/dmadisetti-patch-1/tf-graph/tf-graph-basic.build.html" + return f""" + + """ # Visualizing the network graph. Be sure expand the "mixed" nodes to see their # internal structure. We are going to visualize "Conv2D" nodes. From 73731fd67a90782940736e47d99165adcc1469ed Mon Sep 17 00:00:00 2001 From: Dylan Madisetti Date: Tue, 9 Mar 2021 18:13:03 -0500 Subject: [PATCH 2/2] TF2 compatibility --- tfutils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tfutils.py b/tfutils.py index b20cc2e..4a4990f 100644 --- a/tfutils.py +++ b/tfutils.py @@ -1,4 +1,5 @@ import tensorflow as tf +from tensorflow.core.framework import graph_pb2 import numpy as np from base64 import b64encode from IPython.display import clear_output, Image, display, HTML @@ -15,7 +16,7 @@ def _strip_consts(graph_def, max_const_size=32): tensor = n.attr['value'].tensor size = len(tensor.tensor_content) if size > max_const_size: - tensor.tensor_content = "" % size + tensor.tensor_content = "".format(size).encode() return strip_def def _rename_nodes(graph_def, rename_func):