我在第二行到最后一行代码时遇到以下错误:不确定如何继续。任何人都可以给我一些见解。
ValueError: Tensor("Variable_20:0", shape=(8, 8, 4, 32), dtype=float32_ref) must be from the same graph as Tensor("Variable_20/RMSProp_1:0", shape=(8, 8, 4, 32), dtype=float32_ref).
代码如下:
optimizer = tf.train.RMSPropOptimizer(0.00025, 0.95, 0.95, 0.01)
readout = tf.reduce_mean(tf.reduce_sum(tf.mul(l_readout,a), reduction_indices=1))
cost = tf.reduce_mean(tf.square(tf.sub(y,readout)))
grads = optimizer.compute_gradients(cost, localW)
grad_vals = sess.run([g for (g,v) in grads], feed_dict = {a: val_a, y: val_y, s: val_s})
placeholder_gradients = []
for var in localW:
placeholder_gradients.append( (tf.placeholder('float',shape=var.get_shape()) , var) )
feed_dict = {}
for i in range(len(placeholder_gradients)):
feed_dict[placeholder_gradients[i]] = grad_vals[i]
apply_gradients = optimizer.apply_gradients(placeholder_gradients) #ERROR LINE
apply_gradients.run(feed_dict=feed_dict)
答案 0 :(得分:-1)
这可能与使用示例中未显示的线程有关。我将撤回这个问题,直到我进一步研究如何使用相同图形的线程。