AttributeError:“str”对象没有“queue”ref属性

2024-07-08 11:08:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Tensorflow读取CSV文件:

import tensorflow as tf

reader = tf.TextLineReader()
key, value = reader.read("../input/training.csv")

但是,我在代码的最后一行发现了这个问题:

^{pr2}$

这是什么原因?在


Tags: 文件csvkeyimportreadinputvaluetf
1条回答
网友
1楼 · 发布于 2024-07-08 11:08:53

您需要为您的文件创建一个队列

filename_queue = tf.train.string_input_producer(["../input/training.csv"])

reader = tf.TextLineReader()
key, value = reader.read(filename_queue)

^{} documentation

read(
      queue,
      name=None
  )

[...]

  • queue: A Queue or a mutable string Tensor representing a handle to a Queue, with string work items.

根据API指南的Reading from files section

A typical pipeline for reading records from files has the following stages:

  1. The list of filenames
  2. Optional filename shuffling
  3. Optional epoch limit
  4. Filename queue
  5. A Reader for the file format
  6. A decoder for a record read by the reader
  7. Optional preprocessing
  8. Example queue

上面的tf.train.string_input_producer()调用从项4创建文件名队列,传入一个简单的文件名列表(项1)。tf.TextLineReader()是上述列表中的第5项。

相关问题 更多 >

    热门问题