如何查看Tensorflow的graph

2023-08-17  本文已影响0人  旋风竹影

要查看 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

上一篇 下一篇

猜你喜欢

热点阅读