有一个函数tf.Graph.get_tensor_by_name()。例如:
import tensorflow as tf
c = tf.constant([[1.0, 2.0], [3.0, 4.0]])
d = tf.constant([[1.0, 1.0], [0.0, 1.0]])
e = tf.matmul(c, d, name='example')
with tf.Session() as sess:
test = sess.run(e)
print e.name #example:0
test = tf.get_default_graph().get_tensor_by_name("example:0")
print test #Tensor("example:0", shape=(2, 2), dtype=float32)
0
我无法按名称恢复张量,我什至不知道是否可能。
我有一个创建图的函数:
我想在此函数之外访问变量S1_conv1。我试过了:
但这给了我一个错误:
ValueError:共享不足:不允许使用变量scale_1 / Scale1_first_relu。您是说要在VarScope中设置“ reuse = None”?
但这有效:
我可以解决这个问题
但是我不想那样做。
我认为我的问题是S1_conv1并不是一个真正的变量,它只是一个张量。有什么方法可以做我想要的吗?