19

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 viewing in Tensorboard without needing to annotate variables?

I Tried this:

merged = tf.merge_all_summaries()
writer = tf.train.SummaryWriter("/Users/Name/Desktop/tf_logs", session.graph_def)

But no output was produced. This is using the 0.6 wheel.

This appears to be related: Graph visualisaton is not showing in tensorboard for seq2seq model

4

5 回答 5

20

为了提高效率,tf.train.SummaryWriter日志异步到磁盘。为确保图表出现在日志中,您必须在程序退出之前调用close()flush()在 writer 上。

于 2015-12-23T02:15:52.573 回答
17

您还可以将图形转储为 GraphDef protobuf 并将其直接加载到 TensorBoard 中。您可以在不启动会话或运行模型的情况下执行此操作。

## ... 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)

这将输出一个看起来像这样的文件,具体取决于您的模型的具体情况。

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

在 TensorBoard 中,您可以使用“上传”按钮从磁盘加载它。

于 2015-12-23T16:52:13.693 回答
11

这对我有用:

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

使用“--logdir=logdir/”启动张量板时,图表会自动加载。不需要“上传”按钮。

于 2017-02-07T15:27:38.303 回答
4

为了清楚起见,这就是我使用该.flush()方法并解决问题的方式:

使用以下命令初始化编写器:

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

并将作家与:

writer.add_summary(summary_str, i)
    writer.flush()
于 2016-03-23T12:49:38.927 回答
1

除了这个,没有什么对我有用

# 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()

然后使用 TB 工作

#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'
于 2019-04-14T15:26:57.827 回答