一般情况下,我们得到一个模型后都想知道模型里面的张量,下面分别从ckpt模型和pb模型中读取里面的张量名字。
1.读取ckpt模型里面的张量
首先,ckpt模型需包含以下文件,一个都不能少
然后编写代码,将所有张量的名字都保存到tensor_name_list_ckpt.txt文件中
import tensorflow as tf
#直接读取图的结构,不需要手动重新定义
meta_graph = tf.train.import_meta_graph("model.ckpt.meta")
with tf.Session()as sess:
meta_graph.restore(sess,"D:/Face_recognition_github/20180402-114759/model.ckpt")
tensor_name_list = [tensor.name for tensor in tf.get_default_graph().as_graph_def().node]
with open("tensor_name_list_ckpt.txt"