import tensorflow as tf
def csvread(filelist):
#构造读取文件的队列
file_queue=tf.train.string_input_producer(filelist)
reader=tf.TextLineReader()
key,value=reader.read(file_queue)
records=[["None"],["None"]]
example,label=tf.decode_csv(value,record_defaults=records)
example_batch,label_batch=tf.train.batch([example,label],batch_size=9,num_threads=1,capacity=9)
return example_batch,label_batch
file_name = os.listdir("./data/csvdata/")
filelist=[os.path.join("./data/csvdata/",file) for file in file_name]
example_batch,label_batch=csvread(filelist)
with tf.Session() as sess:
# 定义一个线程协调器
coord = tf.train.Coordinator()
# 开启读文件的线程
threads = tf.train.start_queue_runners(sess, coord=coord)
# 打印读取的内容
print(sess.run([image_batch, label_batch]))
# 回收子线程
coord.request_stop()
coord.join(threads)
【深度学习】tensorflow csv文件的读取
最新推荐文章于 2023-10-10 08:56:31 发布