Joh*_*oft 55 python tensorflow
Tensorflow中的图形对象有一个名为"get_tensor_by_name(name)"的方法.无论如何得到有效张量名称列表?
如果没有,是否有人知道从这里预训练模型inception-v3的有效名称?从他们的例子中,pool_3是一个有效的张量,但是所有这些的列表都很好.我查看了所提到的论文,其中一些层似乎与表1中的大小相对应,但不是全部.
eta*_*ion 55
该论文未准确反映该模型.如果从arxiv下载源代码,则它具有精确的模型描述作为model.txt,其中的名称与已发布模型中的名称密切相关.
要回答您的第一个问题,请sess.graph.get_operations()
为您提供操作列表.对于op,op.name
给出名称并op.values()
给出它生成的张量列表(在inception-v3模型中,所有张量名称都是附加了":0"的op名称,因此pool_3:0
最终产生的张量也是如此)合并运营.)
Pra*_*lli 24
要查看图中的操作(你会看到很多,所以要缩短我在这里只给出了第一个字符串).
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>,)
Run Code Online (Sandbox Code Playgroud)
Aka*_*yal 22
以上答案是正确的.我遇到了一个易于理解/简单的代码来完成上述任务.所以在这里分享: -
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")
Run Code Online (Sandbox Code Playgroud)
您没有事件必须创建会话以查看图中所有操作名称的名称.要做到这一点,你只需要获取一个默认图表tf.get_default_graph()
并提取所有操作:.get_operations
.每个操作都有很多字段,您需要的是名称.
这是代码:
import tensorflow as tf
a = tf.Variable(5)
b = tf.Variable(6)
c = tf.Variable(7)
d = (a + b) * c
for i in tf.get_default_graph().get_operations():
print i.name
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
63624 次 |
最近记录: |