These are chat archives for arita37/tensorflow

13th
Aug 2016
Rabindra Nath Nandi
@robi56
Aug 13 2016 06:29
I am trying to read .csv file by the follwing code

from future import print_function
import tensorflow as tf
import numpy as np
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1

filename = "test.csv"

setup text reader

file_length = file_len(filename)
filename_queue = tf.train.string_input_producer([filename])
reader = tf.TextLineReader(skip_headerlines=0) , csv_row = reader.read(filename_queue)

setuo text reader

listoflists = []
a_list = []
for i in range(0,4):
listoflists.append((list([0])))

record_defaults =listoflists
data = tf.decode_csv(csv_row,record_defaults=record_defaults,field_delim='\t')

turn features back into a tensor

features = tf.pack(data)

print("loading "+ str(features)+ "line(s)\n")

with tf.Session() as sess:
tf.initialize_all_variables().run()

#start populating filename queue
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners()

for i in range(file_length):
    example = sess.run([features])
    print(example)


coord.request_stop()
coord.join()
print("\ndone loading")
The data is
1 0 0 0 0
0 0 1 1 1
1 0 0 0 0
0 0 1 1 1
But it arises the following error
ERROR:tensorflow:Exception in QueueRunner: Attempted to use a closed Session.