Reputation: 20222
I'm trying to read a CSV file using Tensorflow:
import tensorflow as tf
reader = tf.TextLineReader()
key, value = reader.read("../input/training.csv")
However, I get this issue on the last line of the code:
/opt/conda/lib/python3.6/site-packages/tensorflow/python/ops/io_ops.py in read(self, queue, name)
191 queue_ref = queue
192 else:
--> 193 queue_ref = queue.queue_ref
194 if self._reader_ref.dtype == dtypes.resource:
195 return gen_io_ops._reader_read_v2(self._reader_ref, queue_ref, name=name)
AttributeError: 'str' object has no attribute 'queue_ref'
Any idea what could be the cause of this?
Upvotes: 0
Views: 1166
Reputation: 1121972
You need to create a queue for your files:
filename_queue = tf.train.string_input_producer(["../input/training.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
From the tf.TextLineReader().read()
documentation:
read( queue, name=None )
[...]
queue
: A Queue or a mutable string Tensor representing a handle to a Queue, with string work items.
and from the Reading from files section of the API guide:
A typical pipeline for reading records from files has the following stages:
- The list of filenames
- Optional filename shuffling
- Optional epoch limit
- Filename queue
- A Reader for the file format
- A decoder for a record read by the reader
- Optional preprocessing
- Example queue
The tf.train.string_input_producer()
call above creates the filename queue from item 4, passing in a simple list of filenames (item 1). The tf.TextLineReader()
is item 5 on the above list.
Upvotes: 2