我想知道为什么在使用未注释的版本时,此代码中 x_input_data 的实现将无法正常工作,但注释版本将会如此。谁知道原因?我觉得它与指向对象/值的指针有关。谢谢!
import tensorflow as tf
from random import randint
def generate_random_input():
x = []
for a in range(6):
x.append(randint(0,9))
return x
x_input_data = tf.cast(generate_random_input(), tf.float32)
# x_input_data = tf.random_normal([6], mean=-1, stddev=4) <----HERE
q = tf.FIFOQueue(capacity=3, dtypes=tf.float32)
x_input_data = tf.Print(x_input_data, data=[x_input_data], message="Raw inputs data generated:", summarize=6)
enqueue_op = q.enqueue_many(x_input_data)
numberOfThreads = 1
qr = tf.train.QueueRunner(q, [enqueue_op] * numberOfThreads)
tf.train.add_queue_runner(qr)
input = q.dequeue()
input = tf.Print(input, data=[q.size(), input], message="Nb elements left, input:")
# fake graph: START
y = input + 1
# fake graph: END
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for steps in range(100):
sess.run(y)
coord.request_stop()
coord.join(threads)