【问题标题】:How do I "reset" the graph displayed in TensorBoard for a TensroFlow InteractiveSession?如何“重置” TensorBoard 中显示的 TensroFlow InteractiveSession 图表?
【发布时间】:2017-11-02 23:45:28
【问题描述】:

我希望能够查看我在 TensorBoard InteractiveSession 中试验的 TensorFlow 图。

例如我想成为一个操作A然后刷新TensorBoard并在图中看到A,然后执行B并刷新并在图中看到B。然后,如果我决定要更改图表,我想执行一些操作并获得一个干净的状态,这样当我随后输入 AC 时,我只会看到 AC TensorBoard,而不是我目前看到的BC 和两个版本的A

例如,如果我

import tensorflow as tf
sess = tf.InteractiveSession()
# operation A
# operation B
writer = tf.summary.FileWriter(logdir='logdir', graph=sess.graph)
writer.flush()

然后运行

tensorboard --logdir logdir --purge_orphaned_data

我在 TensorBoard 中得到一个图表,显示 AB 符合预期。

如果我稍后执行其他操作

# operation P
# operation Q

这些不会出现在 TensorBoard 中,除非我再次执行:

writer = tf.summary.FileWriter(logdir='_tflog', graph=sess.graph)
writer.flush()

这会创建一个新日志PQ 现在与 TensorBoard 中的 AB 一起出现在图表中。

如果我运行上面的writer 行,则这些操作的每一次额外执行要么在 TensorBoard 中无效,要么显示为一个额外的节点。

如果我想随后删除操作(例如 AP),我似乎需要完全重新启动所有操作(SessionFileWriter 并删除所有旧日志)。

所有这些都令人困惑且难以跟踪(我什至不确定我上面的帐户是否准确!)。

是否有某种方法可以完全重置 TensorBoard 使用的 Graph,以便我可以在 TensorBoard 中仅查看自上次此类重置以来添加的那些图形元素?

【问题讨论】:

    标签: tensorflow tensorboard


    【解决方案1】:

    我是新手,所以 FWIW:我认为部分问题在于图表而不是会话。

    TF 似乎有一个非常粘的默认图。

    非交互式设置中,我必须做两件主要的事情:

    1) 每次都删除旧的 Session 文件 (events.out.tfevents....),这样它们就不会堆积起来,并且

    2) 真正清除图表(通过在我的会话中使用隐藏的默认图表以外的其他内容)以覆盖张量板显示。

    请注意,保持 tensorboard 运行并在 Web 浏览器中刷新 localhost:6006 URL 似乎很好。

    围绕我的主要 Graph 构造代码,我使用了:

    mytfgraph = tf.Graph() # Get something other than the Default Graph
    with mytfgraph.asdefault():
    
        ...lots of good code here...
    
        # Get rid of old Tensorboard graph file and just save new one
        filesindir = os.listdir(your_graph_location) 
        # os. calls may be OS-dependent
        # Make sure there is no subdir as not checking for this!
        for file in filesindir:
            try:        
                delfile = graph_location + file
                os.remove(delfile)
             except: 
                 print('Warning, Tensorboard file not removed')
    
        train_writer = tf.summary.FileWriter(graph_location)
        # Using custom graph as default ("the with wrapper above")
        train_writer.add_graph(tf.get_default_graph()) 
        train_writer.close()
    
        ...down here I run batches using a 'with tf.Session() as sess:'...
    

    由于您使用的是交互式会话(我不太了解),因此图表部分有一个替代方法可以简化您的生活。那是私有方法:tf.reset_default_graph()Tensorboard scalars and graphs duplicated

    Hacky 与否,我没有使用它,因为我只想尝试使用公共方法。

    【讨论】:

      猜你喜欢
      • 2020-11-24
      • 1970-01-01
      • 2016-02-14
      • 1970-01-01
      • 2019-12-22
      • 2019-04-30
      • 2023-03-21
      • 2019-12-31
      • 1970-01-01
      相关资源
      最近更新 更多