[英]Get input and output node name from .ckpt and .meta files tensorflow
I have .meta and .ckpt files of the tensorflow model. 我有张量流模型的.meta和.ckpt文件。 I wanted to know exact input and output node name but I am getting a list of node names by following this .
我想知道确切的输入和输出节点名称,但是通过此操作,我可以得到节点名称的列表。
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: 当我有一个冻结的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)
Can I do something similar for .ckpt or .meta file ? 我可以对.ckpt或.meta文件做类似的事情吗?
The .meta
file contains information about the different node in the tensorflow graph . .meta
文件包含有关tensorflow 图中不同节点的信息。 This has been better explained here . 这在这里得到了更好的解释。
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. 此时,图中不同变量的值分别存储在
checkpoint.data-xxxx-of-xxxx
文件的checkpoint文件夹中。
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.
由于冻结模型是出于服务目的而完成的,因此它将张量流变量转换为常量,从而无需在每个步骤中存储其他信息,例如不同变量的梯度。
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. 如果您仍然想识别您感兴趣的节点,则可以从
.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)
This will create a __tb
folder in your current directory and you can then view the graph by issuing the following command. 这将在当前目录中创建一个
__tb
文件夹,然后您可以通过发出以下命令来查看图形。
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.
您可以从右上角获取节点的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.