从 .ckpt 和 .meta 文件中获取输入和输出节点名称 tensorflow [英] Get input and output node name from .ckpt and .meta files tensorflow

查看:148
本文介绍了从 .ckpt 和 .meta 文件中获取输入和输出节点名称 tensorflow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有张量流模型的 .meta 和 .ckpt 文件.我想知道确切的输入和输出节点名称,但我通过遵循 这个.

I have .meta and .ckpt files of the tensorflow model. I wanted to know exact input and output node name but I am getting a list of node names by following this.

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

When I have a frozen protobuf model, I get the input node name and output node name as the starting and end of the list using this code:

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 文件做类似的事情吗?

Can I do something similar for .ckpt or .meta file ?

推荐答案

.meta 文件包含有关 tensorflow 中不同节点的信息 图表.这在此处有更好的解释.

The .meta file contains information about the different node in the tensorflow graph. This has been better explained here.

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

The values of the different variables in the graph at that moment are stored separately in the checkpoint folder in checkpoint.data-xxxx-of-xxxx file.

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

There is no concept of an input or output node in the normal checkpoint process, as opposed to the case of a frozen model. Freezing a model outputs a subset of the whole tensorflow graph. This subset of the main graph has only those nodes present on which the output node is dependent on. Because freezing a model is done for serving purposes, it converts the tensorflow variables to constants, eliminating the need for storing additional information like gradients of the different variables at each step.

如果您仍想确定您感兴趣的节点,您可以从 .meta 文件中恢复您的图形并在张量板中对其进行可视化.

If you still want to identify the nodes you would be interested in, you can restore your graph from the .meta file and visualize it in 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 文件夹,然后您可以通过发出以下命令查看图表.

This will create a __tb folder in your current directory and you can then view the graph by issuing the following command.

tensorboard --logdir __tb

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

Here is a link to the screenshot of some model with a node selected. You can get the name of the node from the top right corner.

这篇关于从 .ckpt 和 .meta 文件中获取输入和输出节点名称 tensorflow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆