我的。 CSV 文件包含的数据如下所示...... 1 0 0 0 0 0 0 0 0 0 0 0
我正在尝试通过以下代码阅读此.CSV文件
filename = "alpha_test.csv"
#setup text reader
file_length = file_len(filename)
filename_queue = tf.train.string_input_producer([filename])
reader = tf.TextLineReader(skip_header_lines=0)
_, csv_row = reader.read(filename_queue)
#setuo text reader
listoflists = []
a_list = []
for i in range(0,49):
listoflists.append((list([0])))
record_defaults =listoflists
data = tf.decode_csv(csv_row,record_defaults=record_defaults,field_delim='\t')
#turn features back into a tensor
features = tf.pack(data)
print("loading "+ str(features)+ "line(s)\n")
with tf.Session() as sess:
tf.initialize_all_variables().run()
#start populating filename queue
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners()
for i in range(file_length):
example = sess.run([features])
print(example)
coord.request_stop()
coord.join()
print("\ndone loading")
但它给出了以下错误
ERROR:tensorflow:Exception in QueueRunner: Attempted to use a closed Session.
Traceback (most recent call last):......
tensorflow.python.framework.errors.InvalidArgumentError: Field 0 in record 0 is not a valid int32: 1 0
[[Node: DecodeCSV = DecodeCSV[OUT_TYPE=[DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32], field_delim="\t", _device="/job:localhost/replica:0/task:0/cpu:0"](ReaderRead:1, DecodeCSV/record_defaults_0, DecodeCSV/record_defaults_1, DecodeCSV/record_defaults_2, DecodeCSV/record_defaults_3, DecodeCSV/record_defaults_4, DecodeCSV/record_defaults_5, DecodeCSV/record_defaults_6, DecodeCSV/record_defaults_7, DecodeCSV/record_defaults_8, DecodeCSV/record_defaults_9, DecodeCSV/record_defaults_10, DecodeCSV/record_defaults_11, DecodeCSV/record_defaults_12, DecodeCSV/record_defaults_13, DecodeCSV/record_defaults_14, DecodeCSV/record_defaults_15, DecodeCSV/record_defaults_16, DecodeCSV/record_defaults_17, DecodeCSV/record_defaults_18, DecodeCSV/record_defaults_19, DecodeCSV/record_defaults_20, DecodeCSV/record_defaults_21, DecodeCSV/record_defaults_22, DecodeCSV/record_defaults_23, DecodeCSV/record_defaults_24, DecodeCSV/record_defaults_25, DecodeCSV/record_defaults_26, DecodeCSV/record_defaults_27, DecodeCSV/record_defaults_28, DecodeCSV/record_defaults_29, DecodeCSV/record_defaults_30, DecodeCSV/record_defaults_31, DecodeCSV/record_defaults_32, DecodeCSV/record_defaults_33, DecodeCSV/record_defaults_34, DecodeCSV/record_defaults_35, DecodeCSV/record_defaults_36, DecodeCSV/record_defaults_37, DecodeCSV/record_defaults_38, DecodeCSV/record_defaults_39, DecodeCSV/record_defaults_40, DecodeCSV/record_defaults_41, DecodeCSV/record_defaults_42, DecodeCSV/record_defaults_43, DecodeCSV/record_defaults_44, DecodeCSV/record_defaults_45, DecodeCSV/record_defaults_46, DecodeCSV/record_defaults_47, DecodeCSV/record_defaults_48)]]
Caused by op u'DecodeCSV', defined at:
我已经使用以下数据进行了测试
1 0 0 0 0
0 0 1 1 1
1 0 0 0 0
0 0 1 1 1
但它给出了同样的错误
ERROR:tensorflow:Exception in QueueRunner: Attempted to use a closed Session.
答案 0 :(得分:0)
您看到问题的最可能原因是文件第一行中的1和0实际上是由3个空格分隔,而不是制表符。请注意field_delim
在\t
调用中decode_csv
如何正确设置为1 0
,但其似乎读取的值为save()
。这正是如果1和0被三个空格分开会发生的情况,而下一个0则用一个标签分开。
确保文件不包含空格,并且所有分隔符实际上都是tabsl