【问题标题】:OutOfRangeError (see above for traceback): FIFOQueue '_1_batch/fifo_queue' is closed and has insufficient elements (requested 5, current size 0)OutOfRangeError(参见上面的回溯):FIFOQueue '_1_batch/fifo_queue' 已关闭且元素不足(请求 5,当前大小 0)
【发布时间】:2017-06-26 14:53:43
【问题描述】:

我不知道如何解决这个问题,这个错误信息对我定位问题没有用。感谢您的帮助!

这里是 e.csv、D.csv 和 F.csv 中的数据

e.csv: 1,2,3
       4,5,6
       7,8,9
D.csv: 11,12,13
       14,15,16
       17,18,19
F.csv: 21,22,23
       24,25,26
       27,28,29

这是我的代码

import tensorflow as tf
import os

file_dir = './KDD2'
fileNameQueue = []
for file in os.listdir(file_dir):
    fileNameQueue.append(file)

print fileNameQueue


filename_queue = tf.train.string_input_producer(fileNameQueue, shuffle=False)

reader = tf.TextLineReader()
key, value = reader.read(filename_queue)

col1,col2,label = tf.decode_csv(value, record_defaults=[[1],[1],[1]])

example = tf.pack([col1,col2])

example_batch, label_batch = tf.train.batch([example, label], batch_size=5)

with tf.Session() as sess:
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    for i in range(10):
        print example_batch.eval()
    coord.request_stop()
    coord.join(threads)

这是错误信息

root@ubuntumagiclab:/home/magiclab/SAE# python try.py 
['e.csv', 'D.csv', 'F.csv']
Traceback (most recent call last):
  File "try.py", line 30, in <module>
    print example_batch.eval()
  File "/usr/local/lib/python2.7/dist-
packages/tensorflow/python/framework/ops.py", line 575, in eval
    return _eval_using_default_session(self, feed_dict, self.graph, session)
  File "/usr/local/lib/python2.7/dist-
packages/tensorflow/python/framework/ops.py", line 3633, in _eval_using_default_session
    return session.run(tensors, feed_dict)
  File "/usr/local/lib/python2.7/dist-
packages/tensorflow/python/client/session.py", line 766, in run
run_metadata_ptr)
  File "/usr/local/lib/python2.7/dist-
packages/tensorflow/python/client/session.py", line 964, in _run
    feed_dict_string, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-
packages/tensorflow/python/client/session.py", line 1014, in _do_run
target_list, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-
packages/tensorflow/python/client/session.py", line 1034, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue '_0_batch/fifo_queue' is closed and has insufficient elements (requested 5, current size 0)
     [[Node: batch = QueueDequeueMany[_class=["loc:@batch/fifo_queue"], component_types=[DT_INT32, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](batch/fifo_queue, batch/n)]]

Caused by op u'batch', defined at:
  File "try.py", line 24, in <module>
    example_batch, label_batch = tf.train.batch([example, label], batch_size=5)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/input.py", line 692, in batch
    dequeued = queue.dequeue_many(batch_size, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 458, in dequeue_many
self._queue_ref, n=n, component_types=self._dtypes, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 1099, in _queue_dequeue_many
timeout_ms=timeout_ms, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2240, in create_op
original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1128, in __init__
self._traceback = _extract_stack()

OutOfRangeError (see above for traceback): FIFOQueue '_0_batch/fifo_queue' is closed and has insufficient elements (requested 5, current size 0)
 [[Node: batch = QueueDequeueMany[_class=["loc:@batch/fifo_queue"], component_types=[DT_INT32, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](batch/fifo_queue, batch/n)]]

【问题讨论】:

    标签: python csv tensorflow


    【解决方案1】:

    问题在于文件路径。请提供如下所示的完整路径到文件名队列。

    这对我有用:

    fileNameQueue.append('/home/****/Desktop/stackoverflow/data/' +file)
    

    希望这会有所帮助。

    【讨论】:

    • 感谢您的帮助!但这对我不起作用。对于某些文件它可以工作,其他文件它不起作用并抛出此错误消息。我认为问题可能是我创建的 csv 文件?吓死我了……
    • 能否分享失败的 csv 文件(或 csv 文件中的数据)?
    • 我使用了 3 个文件进行数据读取,如上所示。但我找不到错误发生在哪个文件中。
    • 我不认为 csv 文件有问题。我使用 TF1.0 和相同的 csv 数据。我也可以使用 batch_size=100 运行它。你的TF版本是多少?是 TF 0.1 吗??
    • 哦,我犯了一个大错误!问题出在文件路径上。我的程序中的文件路径有问题,我没有找到它。我现在也可以读取数据了,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多