简体   繁体   中英

Tensorflow InvalidArgumentError

I am getting this error when I try and receive the data within a csv file:

InvalidArgumentError (see above for traceback): Field 0 in record 0 is not a valid int32: Symbol [[Node: 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, DecodeCSV/record_defaults_6)]]

The data is columns of Symbol,Date,Open,High,Low,Close,Volume AAB.TO,23-Jun-2017,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)

How do I fix the error?

According to what you've said, your csv files has header_lines(Symbol,Date,Open,High,Low,Close, etc...).

The TextLineReader() Tensorflow's reader can take a parameter( skip_header_lines ) to let you decide if you want to skip the first line, which is the header line or not. By default, the parameter is set None by default. https://www.tensorflow.org/api_docs/python/tf/TextLineReader#reader_ref

You should set it to 1, to ignore the header line. reader = tf.TextLineReader(skip_header_lines=1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM