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

查看:933
本文介绍了从.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)

我可以o .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.

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

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 文件还原图形,并在tensorboard中对其进行可视化。

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天全站免登陆