简体   繁体   English

从.ckpt和.meta文件tensorflow获取输入和输出节点名称

[英]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.

相关问题 如何在tensorflow中找到给定.ckpt.meta文件的输出节点名称 - How to find the output node name of given .ckpt.meta file in tensorflow 使用.ckpt和.meta -files在TensorFlow中使用Inception进行预测 - Use .ckpt and .meta -files to make predictions with Inception in TensorFlow 来自 model.ckpt.meta 文件的 Tensorflow 视图图 - Tensorflow view graph from model.ckpt.meta file Tensorflow:.ckpt文件和.ckpt.meta和.ckpt.index以及.pb文件之间的关系是什么 - Tensorflow : What is the relationship between .ckpt file and .ckpt.meta and .ckpt.index , and .pb file 如何将 tensorflow .meta .data .index 转换为 .ckpt 文件? - how to convert tensorflow .meta .data .index to .ckpt file? 如何使用 Google Cloud 上 Tensorflow Training 中的 model.ckpt 文件进行预测? - How can I use the model.ckpt Files from Tensorflow Training on Google Cloud for making predictions? 如何从 Tensorflow 检查点 (ckpt) 文件预测 BERT-base 句子中的掩码词? - How to predict masked word in a sentence in BERT-base from Tensorflow checkpoint (ckpt) files? Android上的Tensorflow,输入和输出名称 - Tensorflow on Android, input and output name 即使从ckpt文件恢复后,Tensorflow权重也未恢复 - Tensorflow weights not restored even after restoring from ckpt file 从张量流中的inception_v3.ckpt初始化权重 - Initializing weights from inception_v3.ckpt in tensorflow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM