kwotsin
kwotsin

Reputation: 2923

Tensorflow: tensor reshape error together with RandomShuffleQueue out of range error?

I have 2 errors that came together when I tried to run my file:

Out of range: RandomShuffleQueue '_1_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)

The 'requested 1' is actually my batch size. I have tried to reduce my batch_size to 1 to see if the error occurs again. However, I'm unsure why the current size is 0 at all.

InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 357604 values, but the requested shape has 89401

I have referred to an older thread: TensorFlow random_shuffle_queue is closed and has insufficient elements, and I've checked that I've a similar problem since 357604 = 89401 * 4, so I'm wondering where the 4 comes from.

The thread does mention that if I converted my files to TFrecords in int32 and then I read them with uint8 format, then I'll have 4 times more data. However, I can't tell where in my tfrecord file creation did I use int32. I tried to fix the problem by converting my tfrecords file in uint8 forcefully (using the DataSet class from the tensorflow mnist file, i.e. from tensorflow.contrib.learn.python.learn.datasets import mnist, and setting the dtype = tf.uint8 for my dataset), I got another new error I can't identify:

tensorflow.python.framework.errors.InvalidArgumentError: Expected begin[0] == 0 (got 0) and size[0] == 0 (got 1) when input.dim_size(0) == 0
     [[Node: softmax_cross_entropy_loss/Slice_3 = Slice[Index=DT_INT32, T=DT_INT32, _device="/job:localhost/replica:0/task:0/gpu:0"](softmax_cross_entropy_loss/Shape_3, softmax_cross_entropy_loss/Slice_3/begin, softmax_cross_entropy_loss/Slice_3/size)]]

Caused by op u'softmax_cross_entropy_loss/Slice_3', defined at:
  File "train.py", line 103, in <module>
    FLAGS.log_dir)
  File "train.py", line 88, in main
    slim.losses.softmax_cross_entropy(predictions, labels)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/losses/python/losses/loss_ops.py", line 385, in softmax_cross_entropy
    return compute_weighted_loss(losses, weight)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/losses/python/losses/loss_ops.py", line 144, in compute_weighted_loss
    num_present = _num_present(losses, weight)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/losses/python/losses/loss_ops.py", line 179, in _num_present
    [0], [1]), [])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 431, in slice
    return gen_array_ops._slice(input_, begin, size, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 2234, in _slice
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2380, 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 1298, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Expected begin[0] == 0 (got 0) and size[0] == 0 (got 1) when input.dim_size(0) == 0
     [[Node: softmax_cross_entropy_loss/Slice_3 = Slice[Index=DT_INT32, T=DT_INT32, _device="/job:localhost/replica:0/task:0/gpu:0"](softmax_cross_entropy_loss/Shape_3, softmax_cross_entropy_loss/Slice_3/begin, softmax_cross_entropy_loss/Slice_3/size)]]

I'm trying to create train a model using TF-slim eventually. As there are very little tutorials available on the TF-Slim library, I've used the codes from: https://github.com/mnuke/tf-slim-mnist as a reference. Most of my code examples are with reference to the code from this link.

Upvotes: 1

Views: 487

Answers (1)

sygi
sygi

Reputation: 4647

My guess for the first problem is that you need to do:

sess.run(tf.initialize_local_variables())

This problem happens when you don't initialize the number of epochs of a Queue.

Upvotes: 1

Related Questions