保存Tensorflow图以便在Tensorboard中查看而无需汇总操作

时间:2015-12-23 01:30:04

标签: tensorflow tensorboard

我有一个相当复杂的Tensorflow图,我想为了优化目的进行可视化。是否有一个我可以调用的函数,只需保存图形以便在Tensorboard中查看而无需注释变量?

我试过这个:

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

但没有产生任何产出。这是使用0.6轮。

这似乎是相关的: Graph visualisaton is not showing in tensorboard for seq2seq model

5 个答案:

答案 0 :(得分: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中,您可以使用“上传”按钮从磁盘加载它。

答案 1 :(得分:15)

为了提高效率,tf.train.SummaryWriter以异步方式记录到磁盘。要确保图表显示在日志中,您必须在程序退出之前在编写器上调用close()flush()

答案 2 :(得分:9)

这对我有用:

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

使用" - logdir = logdir /"启动张量板时会自动加载图表。否#34;上传"按钮需要。

答案 3 :(得分:4)

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

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

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

并使用编写器:

writer.add_summary(summary_str, i)
    writer.flush()

答案 4 :(得分:0)

除此以外,对我没有任何帮助

package app.shakil.com.dailyexpense.Models;

public class ExpenseModel {
    private int id;
    private String title;
    private String description;
    private String date;
    private int amount;
    private String currency;

public ExpenseModel(){

}

public ExpenseModel(String title,String description,String date,int amount,String currency){
    this.title=title;
    this.description=description;
    this.date=date;
    this.amount=amount;
    this.currency=currency;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String getDate() {
    return date;
}

public void setDate(String date) {
    this.date = date;
}

public int getAmount() {
    return amount;
}

public void setAmount(int amount) {
    this.amount = amount;
}

public String getCurrency() {
    return currency;
}

public void setCurrency(String currency) {
    this.currency = currency;
}
}

然后使用TB有效

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