【问题标题】:Get input and output node name from .ckpt and .meta files tensorflow从 .ckpt 和 .meta 文件中获取输入和输出节点名称 tensorflow
【发布时间】:2019-09-09 11:04:06
【问题描述】:

我有张量流模型的 .meta 和 .ckpt 文件。我想知道确切的输入和输出节点名称,但我通过关注this 获得了节点名称列表。

当我有一个冻结的 protobuf 模型时,我使用以下代码获取输入节点名称和输出节点名称作为列表的开始和结束:

import tensorflow as tf
from tensorflow.python.platform import gfile
GRAPH_PB_PATH = 'frozen_model.pb'
with tf.Session() as sess:
   print("load graph")
   with gfile.FastGFile(GRAPH_PB_PATH,'rb') as f:
       graph_def = tf.GraphDef()
   graph_def.ParseFromString(f.read())
   sess.graph.as_default()
   tf.import_graph_def(graph_def, name='')
   graph_nodes=[n for n in graph_def.node]
   names = []
   for t in graph_nodes:
      names.append(t.name)
   print(names)

我可以为 .ckpt 或 .meta 文件做类似的事情吗?

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

    .meta 文件包含有关 tensorflow graph 中不同节点的信息。这已经更好地解释了here

    此时图中不同变量的值分别存储在checkpoint.data-xxxx-of-xxxx文件的checkpoint文件夹中。

    与冻结模型的情况相反,在正常检查点过程中没有输入或输出节点的概念。冻结模型会输出整个张量流图的子集。主图的这个子集只有输出节点所依赖的那些节点。因为冻结模型是为了服务目的,它会将 tensorflow 变量转换为常量,从而无需在每个步骤存储其他信息,例如不同变量的梯度。

    如果您仍想识别您感兴趣的节点,您可以从.meta 文件中恢复您的图表并在 tensorboard 中将其可视化。

    import tensorflow as tf
    from tensorflow.summary import FileWriter
    
    sess = tf.Session()
    tf.train.import_meta_graph("your-meta-graph-file.meta")
    FileWriter("__tb", sess.graph)
    

    这将在您的当前目录中创建一个__tb 文件夹,然后您可以通过发出以下命令来查看图表。

    tensorboard --logdir __tb
    

    Here 是某个模型的屏幕截图的链接,其中选择了一个节点。您可以从右上角获取节点的名称。

    【讨论】:

    • 当我在终端中运行 tensorboard 命令时,我得到的只是DESKTOP-JQCP6TS:6006 我该怎么做?
    • 键入 localhost:6006 代替(在运行 tensorboard 命令之后)。它应该带你到张量板。
    猜你喜欢
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多