OutOfRangeError:RandomShuffleQueue'_1_shuffle_batch / random_shuffle_queue'

时间:2018-07-25 18:57:05

标签: tensorflow machine-learning tensorflow-datasets tfrecord

这是我用于读取tfrecord文件的代码,它是由Github上的任何未知对象创建的,因此我试图读取它。但是我收到一个错误,如下所示。谁能解决这个问题???

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

data_path = 'train.tfrecords'

with tf.Session() as sess:
   feature = {'train/image': tf.FixedLenFeature([],tf.string),
              'train/label': tf.FixedLenFeature([],tf.int64)}
   filename_queue = tf.train.string_input_producer([data_path],num_epochs=1000)

   reader = tf.TFRecordReader()
   serialized_example = reader.read(queue=filename_queue,name=None)

   features = tf.parse_example(serialized_example,features=feature)

   image = tf.decode_raw(features['train/image'], tf.float32)

   label = tf.cast(features['train/label'], tf.int32)

   image = tf.reshape(image, [224, 224, 3])

   images, labels = tf.train.shuffle_batch([image, label], batch_size=10, capacity=30, num_threads=1,
                                        min_after_dequeue=10)

   init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
   sess.run(init_op)

   coord = tf.train.Coordinator()
   threads = tf.train.start_queue_runners(coord=coord)

   for batch_index in range(5):
      img, lbl = sess.run([images, labels])
      img = img.astype(np.uint8)
      for j in range(6):
        plt.subplot(2, 3, j + 1)
        plt.imshow(img[j, ...])
        plt.title('cat' if lbl[j] == 0 else 'dog')
        plt.show()

   coord.request_stop()

   coord.join(threads)
   sess.close()

这是错误

C:\Users\snklp\Anaconda3\envs\untitled\python.exe C:/Users/snklp/PycharmProjects/untitled/demo3.py
2018-07-26 00:20:14.431963: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2018-07-26 00:20:14.514476: W tensorflow/core/framework/op_kernel.cc:1318] OP_REQUIRES failed at example_parsing_ops.cc:144 : Invalid argument: Could not parse example input, value: 'train.tfrecords:0'
Traceback (most recent call last):
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\client\session.py", line 1322, in _do_call
    return fn(*args)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\client\session.py", line 1307, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\client\session.py", line 1409, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
     [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/snklp/PycharmProjects/untitled/demo3.py", line 33, in <module>
    img, lbl = sess.run([images, labels])
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\client\session.py", line 900, in run
    run_metadata_ptr)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\client\session.py", line 1135, in _run
    feed_dict_tensor, options, run_metadata)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\client\session.py", line 1316, in _do_run
    run_metadata)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\client\session.py", line 1335, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
     [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

Caused by op 'shuffle_batch', defined at:
  File "C:/Users/snklp/PycharmProjects/untitled/demo3.py", line 24, in <module>
    min_after_dequeue=10)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\training\input.py", line 1300, in shuffle_batch
    name=name)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\training\input.py", line 846, in _shuffle_batch
    dequeued = queue.dequeue_many(batch_size, name=name)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\ops\data_flow_ops.py", line 483, in dequeue_many
    self._queue_ref, n=n, component_types=self._dtypes, name=name)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\ops\gen_data_flow_ops.py", line 3479, in queue_dequeue_many_v2
    component_types=component_types, timeout_ms=timeout_ms, name=name)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\framework\ops.py", line 3392, in create_op
    op_def=op_def)
  File "C:\Users\snklp\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\framework\ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

OutOfRangeError (see above for traceback): RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
     [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

Process finished with exit code 1

我是新来的,所以对这些错误了解不多。有人能告诉我这个错误吗?

0 个答案:

没有答案