在设置string_input_producer时,num_epochs似乎并不是队列字符串。
使用下面的代码,程序打印,这是不正确的。
`import tensorflow as tf
sess = tf.InteractiveSession()
filenames = ["1", "2", "3"]
filename_queue = tf.train.string_input_producer(filenames, num_epochs=10)
test_value = tf.convert_to_tensor(filename_queue.size())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
print(sess.run([test_value]))`但如果我干掉num_epochs,
`import tensorflow as tf
sess = tf.InteractiveSession()
filenames = ["1", "2", "3"]
filename_queue = tf.train.string_input_producer(filenames)
test_value = tf.convert_to_tensor(filename_queue.size())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
print(sess.run([test_value]))`它按预期打印3。
还有其他人遇到同样的问题吗?
发布于 2016-07-01 16:38:26
解决方案是添加以下一行:
sess.run(tf.initialize_all_variables())...before启动队列运行程序。tf.train.string_input_producer()函数在内部创建一个TensorFlow变量来跟踪当前的时代索引,并且它必须在第一次使用之前被初始化(当您启动队列运行程序时)。
发布于 2017-01-19 21:05:51
https://stackoverflow.com/questions/38135129
复制相似问题