Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken GraphView #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion tf-graph/tf-graph-basic.build.html
Original file line number Diff line number Diff line change
Expand Up @@ -1053,4 +1053,13 @@ <h2>[[title]]</h2>
</template>
</dom-module>

<script src="tf-graph-basic.build.js"></script></body></html>
<script src="tf-graph-basic.build.js"></script>
<div style="height:600px">
<tf-graph-basic id="custom-graph"></tf-graph-basic>
</div>
<script>
window.onload = (event)=>{
document.getElementById("custom-graph").pbtxt = atob(decodeURI(window.location.hash.substr(1)));
}
</script>
</body></html>
2 changes: 1 addition & 1 deletion tf-graph/tf-graph-basic.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
29 changes: 10 additions & 19 deletions tfutils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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

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)
Expand All @@ -31,24 +33,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 = """
<script>
function load() {{
document.getElementById("{id}").pbtxt = {data};
}}
</script>
<link rel="import" href="{baseURL}/files/tf-graph/tf-graph-basic.build.html" onload=load()>
<div style="height:600px">
<tf-graph-basic id="{id}"></tf-graph-basic>
</div>
""".format(data=repr(str(strip_def)), id='graph' + str(np.random.rand()), baseURL=baseURL)

iframe = """
<iframe seamless style="width:800px;height:620px;border:0" srcdoc="{}"></iframe>
""".format(code.replace('"', '&quot;'))

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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops. Obviously will change this, but looks like this project is stale anyway

return f"""
<iframe id="frame-graph-{id}" seamless src='{page}#{data}' style="width:100%;height:620px;border:0"></iframe>
"""

# Visualizing the network graph. Be sure expand the "mixed" nodes to see their
# internal structure. We are going to visualize "Conv2D" nodes.
Expand Down