Skip to content

TensorFlow tfrecord OutOfRange error #24898

Closed

Description

@MatthewD1993

In src/datasets/h36m_edit.py:

with tf.Session() as sess:
    reader = tf.TFRecordReader()
    coder = ImageCoder()

    fqueue = tf.train.string_input_producer(files, num_epochs=1, shuffle=False, name="input")
    _, example_serialized = reader.read(fqueue)

    sess.run(tf.local_variables_initializer())
    sess.run(tf.global_variables_initializer())

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

    fidx = 0
    total_imgs = 0
    image, image_size, label, center, fname, pose, shape, gt3d, has_smpl3d = parse_example_proto(example_serialized)

    while not coord.should_stop():
        fidx += 1
        tf_filename = out_path% fidx

        print('Starting tfrecord file %s \n' % tf_filename)
        with tf.python_io.TFRecordWriter(tf_filename) as writer:
            for i in tqdm(range(train_shards)):  # min(train_shards, image_bs.shape[0])
                image_v, image_size_v, label_v, center_v, fname_v, pose_v, shape_v, gt3d_v, has_smpl3d_v = sess.run(
                    [image, image_size, label, center, fname, pose, shape, gt3d, has_smpl3d])
                image_s = coder.encode_jpeg(image_v)
                example = convert_to_example_wmosh(image_s, fname_v, image_size_v[0], image_size_v[1],
                                                   label_v, center_v, gt3d_v, pose_v, shape_v)
                writer.write(example.SerializeToString())
                total_imgs += 1

    coord.request_stop()
    coord.join(threads)

Sometimes the inner loop stops before it reaches the maximum iter limit (train_shards) 500.

100%|██████████| 500/500 [00:02<00:00, 225.07it/s]
Starting tfrecord file /home/cdeng/tf_datasets/tf_records_human36m_wjoints/train_modified/train_0011.tfrecord 

 96%|█████████▌| 478/500 [00:02<00:00, 225.58it/s]Starting tfrecord file /home/cdeng/tf_datasets/tf_records_human36m_wjoints/train_modified/train_0012.tfrecord 

100%|██████████| 500/500 [00:02<00:00, 230.37it/s]

And when it writes to the number 625 tfrecord file, there is OutOfRange error (it supposes to finish with more than 3000 tfrecord files, cause human36m train has 1559985 images and each tfrecord contains 500 images). I guess it's because the image queue is not handled correctly, maybe the producer is too slow?

/home/cdeng/tf_datasets/tf_records_human36m_wjoints/train_modified/train_0625.tfrecord 
 36%|███▌      | 180/500 [00:00<00:01, 221.50it/s]2019-01-13 22:47:40.946736: W tensorflow/core/framework/op_kernel.cc:1192] Out of range: FIFOQueue '_0_input' is closed and has insufficient elements (requested 1, current size 0)
	 [[Node: ReaderReadV2 = ReaderReadV2[_device="/job:localhost/replica:0/task:0/cpu:0"](TFRecordReaderV2, input)]]
2019-01-13 22:47:40.946816: W tensorflow/core/framework/op_kernel.cc:1192] Out of range: FIFOQueue '_0_input' is closed and has insufficient elements (requested 1, current size 0)
	 [[Node: ReaderReadV2 = ReaderReadV2[_device="/job:localhost/replica:0/task:0/cpu:0"](TFRecordReaderV2, input)]]

Traceback (most recent call last):
  File "/home/cdeng/star_repos/hmr/src/datasets/h36m_edit.py", line 233, in <module>
    [image, image_size, label, center, fname, pose, shape, gt3d, has_smpl3d])
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 895, in run
    run_metadata_ptr)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1124, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
    options, run_metadata)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue '_0_input' is closed and has insufficient elements (requested 1, current size 0)
	 [[Node: ReaderReadV2 = ReaderReadV2[_device="/job:localhost/replica:0/task:0/cpu:0"](TFRecordReaderV2, input)]]
	 [[Node: ParseSingleExample/ParseExample/ParseExample/_21 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_52_ParseSingleExample/ParseExample/ParseExample", tensor_type=DT_INT64, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

Caused by op u'ReaderReadV2', defined at:
  File "/home/cdeng/star_repos/hmr/src/datasets/h36m_edit.py", line 204, in <module>
    _, example_serialized = reader.read(fqueue)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/ops/io_ops.py", line 194, in read
    return gen_io_ops._reader_read_v2(self._reader_ref, queue_ref, name=name)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_io_ops.py", line 423, in _reader_read_v2
    queue_handle=queue_handle, name=name)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
    op_def=op_def)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/cdeng/.virtualenvs/hmr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1204, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

OutOfRangeError (see above for traceback): FIFOQueue '_0_input' is closed and has insufficient elements (requested 1, current size 0)
	 [[Node: ReaderReadV2 = ReaderReadV2[_device="/job:localhost/replica:0/task:0/cpu:0"](TFRecordReaderV2, input)]]
	 [[Node: ParseSingleExample/ParseExample/ParseExample/_21 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_52_ParseSingleExample/ParseExample/ParseExample", tensor_type=DT_INT64, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]


Process finished with exit code 1

Activity

  1. added
    type:build/install
    type:support
    comp:runtime
    on Jan 15, 2019
  2. jvishnuvardhan commented on Jan 15, 2019

    @jvishnuvardhan
    Contributor

    Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Moreover, please provide as many details as possible to find root cause of the issue. Thanks.

  3. added
    stat:awaiting response
    on Jan 15, 2019
  4. MatthewD1993 commented on Jan 22, 2019

    @MatthewD1993
    Author

    I think the correct way is to handle it with exception handling as suggested in the docs.

  5. added 3 commits that reference this issue on Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

comp:runtimestat:awaiting responsetype:build/installtype:support

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions