【问题标题】:Tensorflow InvalidArgumentErrorTensorFlow InvalidArgumentError
【发布时间】:2017-12-02 12:38:42
【问题描述】:

当我尝试接收 csv 文件中的数据时出现此错误:

InvalidArgumentError(参见上面的回溯):记录 0 中的字段 0 是 不是有效的 int32:符号 [[节点:DecodeCSV = 解码CSV[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,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)

如何修复错误?

【问题讨论】:

    标签: python csv tensorflow


    【解决方案1】:

    根据你所说的,你的 csv 文件有 header_lines(Symbol,Date,Open,High,Low,Close, etc...)。

    TextLineReader() Tensorflow 的阅读器可以带一个参数(skip_header_lines) 让你决定是否要跳过第一行,也就是标题行. 默认情况下,该参数默认设置为无。 https://www.tensorflow.org/api_docs/python/tf/TextLineReader#reader_ref

    您应该将其设置为 1,以忽略标题行。 reader = tf.TextLineReader(skip_header_lines=1)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 2021-04-07
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      相关资源
      最近更新 更多