1

I'm trying to read a tensor from a CSV file and print it. I followed the advice here, but the script still hangs. data.csv consists of one line:

1.5,2.5

Here's the code that reads it:

datafile = tf.train.string_input_producer([os.path.join(os.getcwd(), "data.csv")])
reader = tf.TextLineReader()
_, value = reader.read(datafile)
record_defaults = [[1], [1]]
col1, col2 = tf.decode_csv(value, record_defaults=record_defaults)
result = tf.stack([col1, col2])
config = tf.ConfigProto(inter_op_parallelism_threads=2)
with tf.Session() as sess:
    print(sess.run(result))

Any thoughts?

0

1 Answer 1

1

You're missing this part from the answer you quoted. If you don't add the coordinator and start the queue runners, the queue will never be enqueued and the session will hang, waiting for an element to be enqueued.

with tf.Session() as sess:
  # Start populating the filename queue.
  coord = tf.train.Coordinator()
  threads = tf.train.start_queue_runners(coord=coord)

  for i in range(1200):
    # Retrieve a single instance:
    example, label = sess.run([features, col5])

  coord.request_stop()
  coord.join(threads)
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, thank you. I added the config line because another post recommended it.

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.