Oto recepta ja skopiowane z jednej Alex Mordvintsev głębokim śnie notebook w pewnym momencie
from IPython.display import clear_output, Image, display, HTML
def strip_consts(graph_def, max_const_size=32):
"""Strip large constant values from graph_def."""
strip_def = tf.GraphDef()
for n0 in graph_def.node:
n = strip_def.node.add()
n.MergeFrom(n0)
if n.op == 'Const':
tensor = n.attr['value'].tensor
size = len(tensor.tensor_content)
if size > max_const_size:
tensor.tensor_content = "<stripped %d bytes>"%size
return strip_def
def show_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="https://tensorboard.appspot.com/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()))
iframe = """
<iframe seamless style="width:1200px;height:620px;border:0" srcdoc="{}"></iframe>
""".format(code.replace('"', '"'))
display(HTML(iframe))
Następnie wizualizację aktualny wykres
show_graph(tf.get_default_graph().as_graph_def())
Jeśli wykres jest zapisany jako pbtxt, można zrobić
gdef = tf.GraphDef()
from google.protobuf import text_format
text_format.Merge(open("tf_persistent.pbtxt").read(), gdef)
show_graph(gdef)
Zobaczysz coś takiego
Sieć [DeepDream przepis] (https: // GitHub.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/deepdream/deepdream.ipynb) działa bardzo dobrze, ale TensorBoard używa do narysowania niezrozumiałego wykresu z wewnętrznymi dodatkowymi węzłami TensorFlow dodaje uruchomić swoje operacje. Aby poprawić czytelność, napisałem [artykuł] (https://medium.com/@Pasky/teasing-out-tensorflow-graph-mess-64cf5ece4b00#.scvq1weq2) z pewnymi wytycznymi, aby zdefiniować model, aby uzyskać lepsze obraz tego. – Pasky