Tensorflow csv reader error: "Quote inside a string has to be escaped by another quote"

Tensorflow csv reader error: "Quote inside a string has to be escaped by another quote"

我有一个 csv 文件,我很确定其中没有 ",我正在尝试使用以下代码读取它:

filename_queue = tf.train.string_input_producer(["../data/train_no_empty_rows.txt"])
# train_no_empty_rows

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


record_defaults = [tf.constant(['p'], dtype=tf.string),    # Column 0
               tf.constant(['p'], dtype=tf.string),    # Column 1
               tf.constant(['p'], dtype=tf.string)]   # Column 2 


col1, col2, col3 = tf.decode_csv(
value, record_defaults=record_defaults,field_delim=" ")

features = tf.pack([col2, col3])
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, col1])

  coord.request_stop()
  coord.join(threads)

但是当我 运行 它时,我得到这个错误:

InvalidArgumentError: Quote inside a string has to be escaped by another quote
 [[Node: DecodeCSV_25 = DecodeCSV[OUT_TYPE=[DT_STRING, DT_STRING, DT_STRING], 
field_delim=" ", 
_device="/job:localhost/replica:0/task:0/cpu:0"]
(ReaderRead_25:1, Const_75, Const_76, Const_77)]]

我想我可以调试,但我找不到它引用 csv 文件中的哪个条目的位置有问题。这是一个相当大的 csv 文件,前 100 个左右的条目没有这个问题。正如我所说,我找不到任何 ",并且 ' 似乎在测试中解析得很好。有什么方法可以找到麻烦的条目吗?

谢谢!

找到麻烦条目的一种方法是添加 tf.Print() operator before the tf.decode_csv():

# ...

# Prints out the contents of `key` and `value` every time the op executes.
value = tf.Print(value, [key, value])

col1, col2, col3 = tf.decode_csv(
    value, record_defaults=record_defaults, field_delim=" ")

# ...

失败前最后记录的条目应指示哪个输入无效。希望当您进行此修改时,根本原因会变得明显。