标签:输出 读取 ext import def 数据读取 request default 开启
# -*- coding:utf-8 -*-
import tensorflow as tf
fn_queue=tf.train.string_input_producer(["winequality-white-test.csv"])
reader=tf.TextLineReader(skip_header_lines=1)
key,value=reader.read(fn_queue)
print(key)#文件名及行数
print(value)#按行读取的原始字符串
#fixedacidity,volatileacidity,citric acid,residualsugar,chlorides,freesulfurdioxide,totalsulfurdioxide,density,pH,sulphates,alcohol,quality
recordDefaults=[[1.],[1.],[1.],[1.],[1.],[1.],[1.],[1.],[1.],[1.],[1.],[1.]]
(fixedacidity,volatileacidity,citricacid,residualsugar,chlorides,freesulfurdioxide,totalsulfurdioxide,density,pH,sulphates,alcohol,quality)=tf.decode_csv(value,record_defaults=recordDefaults)
features=tf.stack([fixedacidity,volatileacidity,citricacid,residualsugar,chlorides,freesulfurdioxide,totalsulfurdioxide,density,pH,sulphates,alcohol])
out=quality
init_op=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
#开启协调器
coord=tf.train.Coordinator()
#启动队列填充
threads=tf.train.start_queue_runners(coord=coord)
try:
for i in range(200):
sample,label=sess.run([features,out])
print(sample)
print(label)
print("--------")
except tf.errors.OutOfRangeError:
print("Done!!!")
finally:
coord.request_stop()
coord.join(threads)
print("reading has finished.")
reading has finished.
标签:输出 读取 ext import def 数据读取 request default 开启
原文地址:http://blog.51cto.com/13959448/2333982