TensorFlow:读取CSV文件会永久挂起 [英] TensorFlow: Reading a CSV file hangs forever

查看:1041
本文介绍了TensorFlow:读取CSV文件会永久挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已遵循教程和 csv示例显示似乎没有工作。它永远卡住...

I've followed the tutorial and the csv example shown there doesn't seem to work. It gets stuck forever...

这是代码:

import tensorflow as tf

filename_queue = tf.train.string_input_producer(["file0.csv", "file1.csv"])

reader = tf.TextLineReader()
key, value = reader.read(filename_queue)

# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [[1], [1], [1], [1], [1]]
col1, col2, col3, col4, col5 = tf.decode_csv(
    value, record_defaults=record_defaults)
features = tf.pack([col1, col2, col3, col4])

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)

我使用Tensorflow 0.7.1和Python3。

I'm using Tensorflow 0.7.1 and Python3.

我做错了什么?

我的文件只有这一行:

5,4,3,2,1


推荐答案

感谢您的持久尝试调试这个。事实证明,您遇到了在最近提交中修复的错误,但是该修复还没有使它成为一个版本。有两种可能的修复(获取更多处理器除外) :

Thanks for your persistence on trying to debug this. It turns out that you were running into a bug that was fixed in a recent commit, but the fix hasn't made it into a release yet. There are two possible fixes (other than acquiring more processors):


  1. 升级至每夜二进制发布安装
  1. Upgrade to the nightly binary release or install from source, to get the fix.
  2. In your Python program, add the following to the session creation:

config = tf.ConfigProto(inter_op_parallelism_threads=2)
with tf.Session(config=config) as sess:
  # ...


问题的原因是TensorFlow使用有界线程池来调度ops,修复),读取器操作可能阻塞,如果另一个操作必须在读取器完成之前运行(例如由于生产者 - 消费者关系),这将导致死锁。该修复通过异步运行阅读器来解决此问题。

The reason for the issue is that TensorFlow uses a bounded threadpool for dispatching ops, and (until the fix) the reader op could block, which would lead to deadlock if another op had to run before the reader could complete (for example because of a producer-consumer relationship). The fix addresses this by running the reader asynchronously.

这篇关于TensorFlow:读取CSV文件会永久挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆