簡體   English   中英

Tensorflow InvalidArgumentError

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM