title: Visualizing a TensorFlow graph in Jupyter doesn't work
body: <p>I saw this <a href="https://stackoverflow.com/questions/38189119/simple-way-to-visualize-a-tensorflow-graph-in-jupyter">question</a> about how to visualise a tensorflow graph in Jupyter notebook. I found that this answer comes from <a href="https://stackoverflow.com/questions/38189119/simple-way-to-visualize-a-tensorflow-graph-in-jupyter">this</a> example with just one modification in (<code>tensor.tensor_content = bytes("&lt;stripped %d bytes&gt;"%size, 'utf-8')</code> is replaced by <code>tensor.tensor_content = "&lt;stripped %d bytes&gt;"%size</code>). However if I try to rerun it on <code>tensorflow_inception_graph.pb</code> the visualisation doesn't work: the iframe is white and there is no nodes displayed.</p>
  
  <p>I would highly appreciate if you explain me what I am doing wrong. Here there is a simple example to reproduce the problem.</p>
  
  <p>Import:</p>
  
  <pre class="lang-py prettyprint-override"><code>%matplotlib inline
  %config InlineBackend.figure_format = 'retina'
  
  import tensorflow as tf
  import numpy as np
  
  from IPython.display import clear_output, Image, display, HTML
  </code></pre>
  
  <p>Create graph:</p>
  
  <pre class="lang-py prettyprint-override"><code>graph = tf.Graph()
  sess = tf.InteractiveSession(graph=graph)
  
  x = tf.placeholder(tf.float32, shape=[None, 25, 25, 3], name='x')
  y_true = tf.placeholder(tf.float32, shape=[None, 10], name='y_true')
  y_true_cls = tf.argmax(y_true, dimension=1, name='y_true_cls')
  
  print graph.get_operations()
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>[&lt;tensorflow.python.framework.ops.Operation at 0x115902850&gt;,
   &lt;tensorflow.python.framework.ops.Operation at 0x115902690&gt;,
   &lt;tensorflow.python.framework.ops.Operation at 0x115902b10&gt;,
   &lt;tensorflow.python.framework.ops.Operation at 0x1159029d0&gt;]
  </code></pre>
  
  <p>The visualisation functions:</p>
  
  <pre class="lang-py prettyprint-override"><code>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 &gt; max_const_size:
                  tensor.tensor_content = bytes("&lt;stripped %d bytes&gt;"%size, "utf-8")
      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 = """
          &lt;script&gt;
            function load() {{
              document.getElementById("{id}").pbtxt = {data};
            }}
          &lt;/script&gt;
          &lt;link rel="import" href="https://tensorboard.appspot.com/tf-graph-basic.build.html" onload=load()&gt;
          &lt;div style="height:600px"&gt;
            &lt;tf-graph-basic id="{id}"&gt;&lt;/tf-graph-basic&gt;
          &lt;/div&gt;
      """.format(data=repr(str(strip_def)), id='graph'+str(np.random.rand()))
  
      iframe = """
          &lt;iframe seamless style="width:1200px;height:620px;border:0" srcdoc="{}"&gt;&lt;/iframe&gt;
      """.format(code.replace('"', '&amp;quot;'))
      display(HTML(iframe))
  </code></pre>
  
  <p>The result:</p>
  
  <p><a href="https://i.stack.imgur.com/P3wg1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P3wg1.png" alt="enter image description here"></a></p>
  
  <p><strong>UPD</strong> I tried a simpler example:</p>
  
  <pre><code>tf.reset_default_graph()
  x = tf.ones((), name="x")
  y = tf.ones((), name="y")
  z = tf.add(x, y, name="z")
  show_graph()
  </code></pre>
  
  <p>But it still doesn't work. I suspect the problem is related to Javascript/HTML code that is generated:</p>
  
  <pre><code>    &lt;script&gt;
        function load() {
          document.getElementById(&amp;quot;graph0.746875762596&amp;quot;).pbtxt = 'node {\n  name: &amp;quot;x&amp;quot;\n  op: &amp;quot;Const&amp;quot;\n  attr {\n    key: &amp;quot;dtype&amp;quot;\n    value {\n      type: DT_FLOAT\n    }\n  }\n  attr {\n    key: &amp;quot;value&amp;quot;\n    value {\n      tensor {\n        dtype: DT_FLOAT\n        tensor_shape {\n        }\n        float_val: 1.0\n      }\n    }\n  }\n}\nnode {\n  name: &amp;quot;y&amp;quot;\n  op: &amp;quot;Const&amp;quot;\n  attr {\n    key: &amp;quot;dtype&amp;quot;\n    value {\n      type: DT_FLOAT\n    }\n  }\n  attr {\n    key: &amp;quot;value&amp;quot;\n    value {\n      tensor {\n        dtype: DT_FLOAT\n        tensor_shape {\n        }\n        float_val: 1.0\n      }\n    }\n  }\n}\nnode {\n  name: &amp;quot;z&amp;quot;\n  op: &amp;quot;Add&amp;quot;\n  input: &amp;quot;x&amp;quot;\n  input: &amp;quot;y&amp;quot;\n  attr {\n    key: &amp;quot;T&amp;quot;\n    value {\n      type: DT_FLOAT\n    }\n  }\n}\n';
        }
      &lt;/script&gt;
      &lt;link rel=&amp;quot;import&amp;quot; href=&amp;quot;https://tensorboard.appspot.com/tf-graph-basic.build.html&amp;quot; onload=load()&gt;
      &lt;div style=&amp;quot;height:600px&amp;quot;&gt;
        &lt;tf-graph-basic id=&amp;quot;graph0.746875762596&amp;quot;&gt;&lt;/tf-graph-basic&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Maybe something with <code>&amp;quot</code> and <code>'</code>?</p>