tf.graph visualizer

from IPython.display import clear_output, Image, display, HTML
def strip_consts(graph_def, max_const_size=32):
    
    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):
    
    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 src="//cdnjs.cloudflare.5com/ajax/libs/polymer/0.3.3/platform.js"></script>
        <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('"', '&quot;'))
    display(HTML(iframe))
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文链接 《Python数据分析》(Python for Data Analysis, 2nd Edition)第...
    李绍俊阅读 8,621评论 0 5
  • 我很小的时候,就在作文里写长大了我要去大城市,上海就是一座大城市。如今,甚至想不起来为什么小时候会有这样执着的想法...
    目分目分目分阅读 533评论 4 4
  • 当我站在冷风里,在枯黄的孱灯下,我望见了你。你用双手拖住花的脸庞,轻声细语。昨日的绿叶,又败了几许。 骄阳似火,玫...
    描不出阅读 280评论 1 0
  • 我怕拔牙 因为 怕疼一下的麻药 还有永远的缺失 我不怕剪指甲 因为 剪掉会长新的 你是我的牙 我却只是指甲
    颐贤妞阅读 272评论 0 0
  • 1、平等 真正的爱情一定是建立在平等的基础上,这也是爱情第一要义。现实生活中确实经常存在“谁先追的谁”,这就像买彩...
    于毅燊阅读 544评论 0 0