0
我有一个关于未显示张量的问题。 我编码如下,我期望有张名称为'ttt','l1a'或'l1_maxpool'的张量,但当tf.all_variables函数看不到时。 但是通过在该位置切换断点来看,它们存在。Tensorflow:未显示张量
是有原因,他们没有显示或其他原因,我应该修改代码? 在此先感谢。
import tensorflow as tf
def init_weights(shape, name):
return tf.Variable(tf.random_normal(shape, stddev=0.01), name=name)
X = tf.placeholder("float", [None, 28, 28, 1])
Y = tf.placeholder("float", [None, 10])
w = init_weights([3, 3, 1, 32], 'w')
w2 = init_weights([3, 3, 32, 64], 'w2')
w3 = init_weights([3, 3, 64, 128], 'w3')
w4 = init_weights([128 * 4 * 4, 625], 'w4')
w_o = init_weights([625, 10], 'w_o')
ttt = tf.nn.conv2d(X, w, strides=[1, 1, 1, 1], padding='SAME', name='ttt')
l1a = tf.nn.relu(ttt, name='l1a')
l1 = tf.nn.max_pool(l1a, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME', name='l1_maxpool')
with tf.Session() as sess:
tf.initialize_all_variables().run()
z_ttt = tf.get_default_graph().get_tensor_by_name(ttt.name)
z_l1 = tf.get_default_graph().get_tensor_by_name(l1.name)
tensors = tf.all_variables()
for k in range(len(tensors)):
print tensors[k].name
kk = 0;
'tf.all_variables()'返回变量列表,'ttt'是'张量'而不是'变量'。这就是“张量”中不存在“ttt”的原因 – xxi