sess = tf.Session()
op = sess.graph.get_operations()
[m.values() for m in op][1]
out:
(<tf.Tensor 'conv1/weights:0' shape=(4, 4, 3, 32) dtype=float32_ref>,)
import tensorflow as tf
def printTensors(pb_file):
# read pb into graph_def
with tf.gfile.GFile(pb_file, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
# import graph_def
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def)
# print operations
for op in graph.get_operations():
print(op.name)
printTensors("path-to-my-pbfile.pb")
查看图中的操作(您将看到许多操作,因此简而言之,我在这里只给出了第一个字符串)。
这篇论文没有准确地反映这个模型。如果您从arxiv下载源代码,它有一个精确的模型描述model.txt,其中的名称与发布的模型中的名称有着强烈的关联。
为了回答您的第一个问题,
sess.graph.get_operations()
提供了一个操作列表。对于op,op.name
为您提供名称,op.values()
为您提供它生成的张量列表(在inception-v3模型中,所有张量名称都是附加“:0”的op名称,因此pool_3:0
是最终池op生成的张量。)以上答案是正确的。我在上面的任务中遇到了一个易于理解/简单的代码。所以在这里分享它:
相关问题 更多 >
编程相关推荐