0

I am using tf.contrib.learn.ReadBatchFeatures (https://www.tensorflow.org/versions/master/api_docs/python/contrib.learn/input_processing#read_batch_features) to read in Example protos as part of my input function, which returns a dict of Tensor objects. After training my model, calling predict on my Estimator returns one batch of predictions as an array, which I would like to compare to the known values.

I try to obtain the known values by calling tf.Session().run(labels), where labels is a Tensor of known values, returned from the input function. However, at this point, my program hangs. I suspect it is stuck in an infinite loop reading labels from the disk, rather than just reading one batch as I would like.

Is this the correct way to obtain one batch of values in the labels Tensor?

Edit: I have tried to start the queue runners, is the following correct?

_, labels = eval_input_fn()
with tf.Session().as_default():
  tf.local_variables_initializer()
  tf.train.start_queue_runners()
  label_values = labels.eval()
print(label_values)
3
  • 1
    maybe you didn't start queue runners and your queue is empty? Reads from empty queue hang Commented Jan 10, 2017 at 3:45
  • Thanks, I remember now that the documentation mentions this, but I forgot about it. My session still hangs though, can you tell what's wrong? Commented Jan 10, 2017 at 6:03
  • Add timeout to see what operation is hanging, something like config = tf.ConfigProto(); config.operation_timeout_in_ms=60000; sess= tf.InteractiveSession(config=config) Commented Jan 10, 2017 at 6:15

1 Answer 1

2

The whole setup you need is:

_, labels = eval_input_fn()

with tf.Session() as sess:
        sess.run([
            tf.local_variables_initializer(),
            tf.global_variables_initializer()
        ])

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

        try:
            while not coord.should_stop():
                print(sess.run(label))

        except tf.errors.OutOfRangeError as error:
            coord.request_stop(error)
        finally:
            coord.request_stop()
            coord.join(threads)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.