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

tensorflow-读取多个文件

时间:2018-11-21 21:08:15      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:cer   rap   读取   from   reads   ret   book   creat   filename   

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Sat Sep 15 10:54:53 2018 @author: myhaspl @email:myhaspl@myhaspl.com 读取多个文件 """ import tensorflow as tf import os validateCount=10 sampleCount=10 testCount=10 g=tf.Graph() with g.as_default(): def inputFromFile(fileName,skipLines=1): #生成文件名队列 fileNameQueue=tf.train.string_input_producer(fileName) #生成记录键值对 reader=tf.TextLineReader(skip_header_lines=skipLines) key,value=reader.read(fileNameQueue) return key,value with tf.name_scope("inputSample"): mykey,mysamples=inputFromFile([os.getcwd()+"/1-1.csv",os.getcwd()+"/1-2.csv"],1) with tf.Session(graph=g) as sess: # 开始产生文件名队列 coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) num_examples = 0 try: while True: key,value = sess.run([mykey, mysamples]) print(key,value) num_examples += 1 except tf.errors.OutOfRangeError: print ("There are", num_examples, "examples") coord.request_stop() coord.join(threads)

1-1.csv
x1,x2,y
6.148,72,35.88
0,33.6,0.627
11,50,1
1.89,66,23
94,28.1,0.167
22,21,0.9

1-2.csv
x1,x2,y
11,21,10
1,41,39
10,32,4
2.14,91.2,0.92
109.3,19.03,81.02
...
(‘/Volumes/MYHASPL/AI_BOOK/src/1-1.csv:4‘, ‘11,50,1‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-1.csv:5‘, ‘1.89,66,23‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-1.csv:6‘, ‘94,28.1,0.167‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-1.csv:7‘, ‘22,21,0.9‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:2‘, ‘11,21,10‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:3‘, ‘1,41,39‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:4‘, ‘10,32,4‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:5‘, ‘2.14,91.2,0.92‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:6‘, ‘109.3,19.03,81.02‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:2‘, ‘11,21,10‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:3‘, ‘1,41,39‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:4‘, ‘10,32,4‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:5‘, ‘2.14,91.2,0.92‘)
(‘/Volumes/MYHASPL/AI_BOOK/src/1-2.csv:6‘, ‘109.3,19.03,81.02‘)

tensorflow-读取多个文件

标签:cer   rap   读取   from   reads   ret   book   creat   filename   

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

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