如何查看Tensorflow的graph

要查看 TensorFlow 的 session graph 结构,可以使用以下步骤:

创建一个 TensorFlow 的 Session 对象。

import  tensorflow as tf

# 创建一个 TensorFlow 的 Session 对象

sess = tf.Session()

使用 tf.get_default_graph() 函数获取默认的 graph。

# 获取默认的 graph

graph = tf.get_default_graph()

使用 graph.as_graph_def() 函数将 graph 转换为 GraphDef 对象。

# 将 graph 转换为 GraphDef 对象

graph_def = graph.as_graph_def()

使用 graph_def 对象的 node 属性可以查看 graph 中的所有节点。

# 遍历所有节点

for node in graph_def.node:

    print(node.name)

通过以上步骤,可以查看 TensorFlow 的 session

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容