Save Tensorflow graph for viewing in Tensorboard without summary operations

后端 未结 5 2236
南旧
南旧 2021-01-01 17:55

I have a rather complicated Tensorflow graph that I\'d like to visualize for optimization purposes. Is there a function that I can call that will simply save the graph for v

相关标签:
5条回答
  • 2021-01-01 18:01

    You can also dump the graph as a GraphDef protobuf and load that directly in TensorBoard. You can do this without starting a session or running the model.

    ## ... create graph ...
    >>> graph_def = tf.get_default_graph().as_graph_def()
    >>> graphpb_txt = str(graph_def)
    >>> with open('graphpb.txt', 'w') as f: f.write(graphpb_txt)
    

    This will output a file that looks something like this, depending on the specifics of your model.

    node {
      name: "W"
      op: "Const"
      attr {
        key: "dtype"
        value {
          type: DT_FLOAT
        }
      }
    ...
    version 1
    

    In TensorBoard you can then use the "Upload" button to load it from disk.

    0 讨论(0)
  • 2021-01-01 18:01

    For all clarity, this is how I used the .flush() method and resolved the issue:

    Initialize the writer with:

    writer = tf.train.SummaryWriter("/home/rob/Dropbox/ConvNets/tf/log_tb", sess.graph_def)
    

    and use the writer with:

    writer.add_summary(summary_str, i)
        writer.flush()
    
    0 讨论(0)
  • 2021-01-01 18:21

    This worked for me:

    graph = tf.Graph()
    with graph.as_default():
        ... build graph (without annotations) ...
    writer = tf.summary.FileWriter(logdir='logdir', graph=graph)
    writer.flush()
    

    The graph is loaded automatically when launching tensorboard with "--logdir=logdir/". No "upload" button needed.

    0 讨论(0)
  • 2021-01-01 18:28

    For efficiency, the tf.train.SummaryWriter logs asynchronously to disk. To ensure that the graph appears in the log, you must call close() or flush() on the writer before the program exits.

    0 讨论(0)
  • 2021-01-01 18:28

    Nothing worked for me except this

    # Helper for Converting Frozen graph from Disk to TF serving compatible Model
    def get_graph_def_from_file(graph_filepath):
      tf.reset_default_graph()
      with ops.Graph().as_default():
        with tf.gfile.GFile(graph_filepath, 'rb') as f:
          graph_def = tf.GraphDef()
          graph_def.ParseFromString(f.read())
          return graph_def
    
    #let us get the output nodes from the graph
    graph_def =get_graph_def_from_file('/coding/ssd_inception_v2_coco_2018_01_28/frozen_inference_graph.pb')
    
    with tf.Session(graph=tf.Graph()) as session:
        tf.import_graph_def(graph_def, name='')
        writer = tf.summary.FileWriter(logdir='/coding/log_tb/1', graph=session.graph)
        writer.flush()
    
    

    Then using TB worked

    #ssh -L 6006:127.0.0.1:6006 root@<remoteip> # for tensor board - in your local machine type 127.0.0.1
    !tensorboard --logdir '/coding/log_tb/1'
    
    0 讨论(0)
提交回复
热议问题