Python 在 tensorboard 中创建日志目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37128652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:54:42  来源:igfitidea点击:

Creating log directory in tensorboard

pythontensorflowtensorboard

提问by Shawn Imm

I am trying to learn how to use tensorboard and I would like to have it run in my program. I do not understand how to create a log directory. These are the lines I have for running tensorboard.

我正在尝试学习如何使用 tensorboard,我希望它在我的程序中运行。我不明白如何创建日志目录。这些是我运行张量板的线路。

   summary_writer = tf.train.SummaryWriter('/tensorflow/logdir', sess.graph_def)
   tensorboard --logdir=tensorflow/logdir

The error message that I got was

我得到的错误信息是

Cannot assign to operator

回答by Phillip Bock

This line needs to be in your code (the python script), as it seems you put it:

这一行需要在您的代码(python 脚本)中,就像您所说的那样:

summary_writer = tf.train.SummaryWriter('/tensorflow/logdir', sess.graph_def)

summary_writer = tf.train.SummaryWriter('/tensorflow/logdir', sess.graph_def)

This line, however, you have to call from linux (and not from within the script):

但是,这一行您必须从 linux 调用(而不是从脚本中调用):

tensorboard --logdir=tensorflow/logdir

张量板 --logdir=tensorflow/logdir

However, there is a lot more you need to do, before tensorboard really runs: How to create a Tensorflow Tensorboard Empty Graph

但是,在 tensorboard 真正运行之前,您还需要做很多事情: 如何创建 Tensorflow Tensorboard Empty Graph

回答by WY Hsu

The tutorial might disclose not very clear on the TensorFlow official website

TensorFlow官网上的教程可能披露的不是很清楚

I have stuck in the same issue before

我以前遇到过同样的问题

But in order not to confuse you, i still use it as a guide here

但为了不让你迷惑,我还是在这里用它作为指南

First Part (lines of codes in .py file)

第一部分(.py 文件中的代码行)

Just skip to class tf.train.SummaryWriterin official guide

只需跳到官方指南中的tf.train.SummaryWriter 类

First, you need this lines of code in your .py file to create a dataflow graph

首先,您需要在 .py 文件中使用这几行代码来创建数据流图

In tensorflow, a session is where the graph been created

在 tensorflow 中,会话是创建图形的地方

#...create a graph...
# Launch the graph in a session.
sess = tf.Session()

Then, you also need to type in these lines into your code

然后,您还需要在代码中输入这些行

# Create a summary writer, add the 'graph' to the event file.
writer = tf.train.SummaryWriter(< directory name you create>, sess.graph)

The logs folder will be generated in the directoryyou assigned after the .py file you created is executed

执行你创建的.py文件后会在你指定的目录下生成logs文件夹

Hereis the sample code you can use

是您可以使用的示例代码

Second Part (lines of code in your linux terminal)

第二部分(Linux 终端中的代码行)

In your Linux terminal window, type in

在 Linux 终端窗口中,输入

tensorboard --logdir="path of your log file"

It will link to your log file automatically

它会自动链接到您的日志文件

Last step (key in link into your browser)

最后一步(在浏览器中输入链接)

After key in

输入后

tensorboard --logdir="path of your log file"

It will generate a http link ,ex http://666.6.6.6:6006

它将生成一个 http 链接,例如http://666.6.6.6:6006

Copy the http link into your web browser

将 http 链接复制到您的 Web 浏览器中

Enjoy it!

好好享受!

Be careful

当心

Do not go to the directory where the log file is beforekey in the line of code above

不要去上面那行代码中key之前的日志文件所在的目录

It might miss the log file

它可能会错过日志文件

Thisyoutube video will explain more explicitly about this at 9:40

这个youtube 视频将在 9:40 更明确地解释这一点

You also can take a look of how to launch tensorboard on official guide

您还可以在官方指南中查看如何启动 tensorboard

Hope you can show your data graph ASAP~

希望你能尽快展示你的数据图~