码迷,mamicode.com
首页 > 其他好文 > 详细

tensorflow-文件数据读取

时间:2018-12-21 21:12:18      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:输出   读取   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.")

以白酒品质样本文件为例,输出结果如下:
...
...
[6.100e+00 2.700e-01 4.300e-01 7.500e+00 4.900e-02 6.500e+01 2.430e+02
9.957e-01 3.120e+00 4.700e-01 9.000e+00]
5.0

reading has finished.

tensorflow-文件数据读取

标签:输出   读取   ext   import   def   数据读取   request   default   开启   

原文地址:http://blog.51cto.com/13959448/2333982

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!