那里,我是tensorflow的新手,当我尝试tf.train.range_input_producer时,它在我的代码中不起作用:
import tensorflow as tf
if __name__ == '__main__':
with tf.Graph().as_default():
with tf.Session() as sess:
queue = tf.train.range_input_producer(tf.Variable(5, tf.int8), num_epochs=1, shuffle=True, seed=None,
capacity=32)
# Start input enqueue threads.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
# Run training steps or whatever
print('queue size:{}'.format(sess.run(queue.size())))
coord.request_stop()
# Terminate as usual. It is innocuous to request stop twice.
coord.join(threads)
sess.close()
我的队列大小为:0
我的代码出了什么问题?提前感谢!
答案 0 :(得分:0)
您需要在启动队列运行程序之前初始化本地和全局变量。
sess.run([tf.local_variables_initializer(), tf.global_variables_initializer()])