【问题标题】:A simple case of Graph visualization in TensorFlow 2.0TensorFlow 2.0 中 Graph 可视化的简单案例
【发布时间】:2019-03-30 15:30:59
【问题描述】:

我想简单地定义一个模型并在 TensorBoard 中可视化它的图形以进行初步的架构检查。因此,我不想为此计算任何东西。

在 TensorFlow 1.X 中,很容易在 tf.Session() 中实现,我可以简单地 flush() 一个摘要文件编写器。

在 TensorFlow 2.0 中,没有 tf.Session(),因此问题是如何实现它?

以下是示例代码。为了在 TensorBoard 中编写图形结构,我需要添加哪些内容?

from nets import i3d
import tensorflow as tf

def i3d_output(model, x):
    out, _ = model(x)
    return out

tf.compat.v1.disable_eager_execution()
x = tf.random.uniform(shape=(4,179,224,224,3))
model = i3d.InceptionI3d()
net = i3d_output(model, x)
train_summary_writer = tf.summary.create_file_writer('/home/uujjwal/bmvc2019')

【问题讨论】:

    标签: tensorflow tensorflow2.0


    【解决方案1】:

    在图形模式下使用这个:

    from tensorflow.python.summary.writer.writer import FileWriter
    FileWriter('logs/', graph=tf.compat.v1.get_default_graph()).close()
    

    或者这个:

    tf.compat.v1.summary.FileWriter('log/', graph=tf.compat.v1.get_default_graph()).close()
    

    在开幕式中不需要。

    【讨论】:

    • AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
    • 是的,忘了tf.compat.v1。刚刚更新了我的问题
    • 这个很好用。一个推测性的问题,但您认为不使用tf.compat.v1 无法做某事是TF2.0 的非急切模式的缺陷吗?
    • 在 TF2 中,您应该使用急切执行,这应该是一件“好事”。你可以做类似import tensorflow.compat.v1 as tf1 的事情来减轻痛苦:-)
    • 这一切看起来就像一个巨大的拐杖。是否有 TF2.0 的原生方式来做到这一点?
    猜你喜欢
    • 2016-11-06
    • 2023-03-25
    • 2020-01-26
    • 1970-01-01
    • 2011-02-01
    • 2020-10-13
    • 2011-09-02
    • 2018-01-19
    • 2017-01-20
    相关资源
    最近更新 更多