Jupyter에서 Tensorboard 시각화 하는 법

2019. 5. 1. 17:26분석 Python/Tensorflow

728x90

모델 아키텍추 구성하고

 

tensorboard() 함수 만든 것을 시행하면 jupyter에 tensorboard가 켜진다!

 

def _strip_consts( graph_def):

        from IPython.display import clear_output, Image, display, HTML

        """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)

        return strip_def





def _show_graph( graph_def):

    from IPython.display import clear_output, Image, display, HTML

    """Visualize TensorFlow graph."""

    if hasattr(graph_def, 'as_graph_def'):

        graph_def = graph_def.as_graph_def()

    strip_def = _strip_consts(graph_def)

    code = """

        <script>

        function load() {{

            document.getElementById("{id}").pbtxt = {data};

        }}

        </script>

       

        <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:100%;height:620px;border:0" srcdoc="{}"></iframe>

    """.format(code.replace('"', '&quot;'))

    display(HTML(iframe))



def tensorboard():

    _show_graph(tf.get_default_graph().as_graph_def())
728x90