TensorFlow tf.decode_csv()无法识别行尾字符

时间:2017-04-26 20:54:05

标签: csv tensorflow

我正在尝试在TensorFlow中读取CSV文件。

record_defaults = [[0.0], [0.0]]
data = tf.decode_csv(r"C:\Users\USER.NAME\Desktop\tmp.txt", record_defaults=record_defaults)
sess = tf.InteractiveSession(config=tf.ConfigProto(log_device_placement=True))

sess.run(tf.global_variables_initializer())

print(sess.run(data))

sess.close()

其中tmp.txt是一个简单的CSV:

1.0,4.0
-.3,1.2

请注意,我正在运行Windows,而Notepad ++显示我的行以'\ r \ n'结尾(CRLF)。

运行上面的代码时出现以下错误,这告诉我,tensorflow无法识别行尾字符:

InvalidArgumentError                      Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in 
_do_call(self, fn, *args)

   1021     try:
-> 1022       return fn(*args)
   1023     except errors.OpError as e:

C:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
   1003                                  feed_dict, fetch_list, target_list,
-> 1004                                  status, run_metadata)
   1005 

C:\Anaconda3\Lib\contextlib.py in __exit__(self, type, value, traceback)
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:

C:\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status()
    465           compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466           pywrap_tensorflow.TF_GetCode(status))
    467   finally:

InvalidArgumentError: Expect 2 fields but have 1 in record 0
     [[Node: DecodeCSV = DecodeCSV[OUT_TYPE=[DT_FLOAT, DT_FLOAT], field_delim=",", _device="/job:localhost/replica:0/task:0/cpu:0"](DecodeCSV/records, DecodeCSV/record_defaults_0, DecodeCSV/record_defaults_1)]]

即使我将分隔符更改为空格或制表符,错误仍然存​​在。

我搜索了Google / StackOverflow,但未能找到类似的错误。任何帮助表示赞赏。谢谢!

0 个答案:

没有答案