[英]Tensorflow InvalidArgumentError
尝试在csv文件中接收数据时出现此错误:
InvalidArgumentError(请参见上面的追溯):记录0中的字段0不是有效的int32:符号[[节点:DecodeCSV = DecodeCSV [OUT_TYPE = [DT_INT32,DT_INT32,DT_INT32,DT_INT32,DT_INT32,DT_INT32,DT_INT32],field_delim =“, “,_device =” / job:localhost / replica:0 / task:0 / cpu:0“](ReaderReadV2: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,解码CSV / record_defaults_6)]]
数据是Symbol,Date,Open,High,Low,Close,Volume AAB.TO的列,2017年6月23日,0.13,0.13,0.13,0.13,500
import tensorflow as tf
tf.reset_default_graph()
filename_queue = tf.train.string_input_producer(["D:\data\TSX_20170623.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], [1], [1]]
col1, col2, col3, col4, col5, col6, col7 = tf.decode_csv(
value, record_defaults=record_defaults)
features = tf.stack([col1, col2, col3, col4, col5, col6, col7])
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(12):
# Retrieve a single instance:
Symbol, label = sess.run([features, col7])
coord.request_stop()
coord.join(threads)
如何解决错误?
根据您所说的,您的csv文件具有header_lines(符号,日期,打开,高,低,关闭等)。
Tensorflow的TextLineReader() Tensorflow的阅读器可以使用参数( skip_header_lines )来决定是否要跳过第一行,即标题行。 默认情况下,该参数默认设置为“无”。 https://www.tensorflow.org/api_docs/python/tf/TextLineReader#reader_ref
您应该将其设置为1,以忽略标题行。 reader = tf.TextLineReader(skip_header_lines=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.