所以我一直在阅读有关排队和排队如何在tensorflow中工作的问题,而且我一直在努力创建一个文件名队列并从中拉出来。
不幸的是,如果我在启动线程后立即尝试出列,我会收到错误。是否有一个原因?如果我进入1秒钟的睡眠计时器,它将会出错。如果没有,它有时会起作用,但通常会抛出异常(如下面的代码所示)
import tensorflow as tf
import time
with tf.Graph().as_default():
filename_list = ['data_batch_{}.mat'.format(i+1) for i in range(5)]
filename_queue = tf.train.string_input_producer(filename_list)
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
#time.sleep(1) # If I uncomment this it works
for i in range(5):
print(sess.run(filename_queue.dequeue()))
coord.request_stop()
coord.join(threads)
抛出异常:
---------------------------------------------------------------------------
NotFoundError Traceback (most recent call last)
<ipython-input-28-cf6ab7b71f22> in <module>()
10 #time.sleep(1)
11 for i in range(5):
---> 12 print(sess.run(filename_queue.dequeue()))
13
14 coord.request_stop()
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
331 try:
332 result = self._run(None, fetches, feed_dict, options_ptr,
--> 333 run_metadata_ptr)
334 if run_metadata:
335 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
571 try:
572 results = self._do_run(handle, target_list, unique_fetches,
--> 573 feed_dict_string, options, run_metadata)
574 finally:
575 # The movers are no longer used. Delete them.
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
646 if handle is None:
647 return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
--> 648 target_list, options, run_metadata)
649 else:
650 return self._do_call(_prun_fn, self._session, handle, feed_dict,
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _do_call(self, fn, *args)
666 except KeyError:
667 pass
--> 668 raise type(e)(node_def, op, message)
669
670 def _extend_graph(self):
NotFoundError: FetchOutputs node input_producer_Dequeue:0: not found
答案 0 :(得分:1)
感谢您告诉我们这个问题。我已经提交了相应的 GitHub issue,并准备了一个修复程序,它应该很快出现在存储库中。
与此同时,通过在开始会话之前创建单个dequeue()
操作,以下代码应该有效:
import tensorflow as tf
with tf.Graph().as_default():
filename_list = ['data_batch_{}.mat'.format(i+1) for i in range(5)]
filename_queue = tf.train.string_input_producer(filename_list)
dequeued_t = filename_queue.dequeue()
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
for i in range(5):
print(sess.run(dequeued_t))
coord.request_stop()
coord.join(threads)