2
2
3
3
"""
4
4
@author: Songgx
5
- @file: 0501_tf_input_csv .py
5
+ @file: 0501_tf_input_csv_test .py
6
6
@time: 11/28/16 4:20 PM
7
7
"""
8
8
9
9
from __future__ import print_function
10
10
import tensorflow as tf
11
11
12
+
12
13
def file_len (fname ):
13
14
with open (fname ) as f :
14
15
for i , l in enumerate (f ):
15
16
pass
16
17
return i + 1
17
18
19
+
18
20
filename = "data/csv_test_data.csv"
19
21
20
22
# setup text reader
@@ -24,25 +26,25 @@ def file_len(fname):
24
26
_ , csv_row = reader .read (filename_queue )
25
27
26
28
# setup CSV decoding
27
- record_defaults = [[0 ],[0 ],[0 ],[0 ],[0 ]]
28
- col1 ,col2 ,col3 ,col4 ,col5 = tf .decode_csv (csv_row , record_defaults = record_defaults )
29
+ record_defaults = [[0 ], [0 ], [0 ], [0 ], [0 ]]
30
+ col1 , col2 , col3 , col4 , col5 = tf .decode_csv (csv_row , record_defaults = record_defaults , field_delim = " " )
29
31
30
32
# turn features back into a tensor
31
- features = tf .pack ([col1 ,col2 ,col3 ,col4 ])
33
+ features = tf .pack ([col1 , col2 , col3 , col4 ])
32
34
33
35
print ("loading, " + str (file_length ) + " line(s)\n " )
34
36
with tf .Session () as sess :
35
- tf .initialize_all_variables ().run ()
37
+ tf .initialize_all_variables ().run ()
36
38
37
- # start populating filename queue
38
- coord = tf .train .Coordinator ()
39
- threads = tf .train .start_queue_runners (coord = coord )
39
+ # start populating filename queue
40
+ coord = tf .train .Coordinator ()
41
+ threads = tf .train .start_queue_runners (coord = coord )
40
42
41
- for i in range (file_length ):
42
- # retrieve a single instance
43
- example , label = sess .run ([features , col5 ])
44
- print (example , label )
43
+ for i in range (file_length ):
44
+ # retrieve a single instance
45
+ example , label = sess .run ([features , col5 ])
46
+ print (example , label )
45
47
46
- coord .request_stop ()
47
- coord .join (threads )
48
- print ("\n done loading" )
48
+ coord .request_stop ()
49
+ coord .join (threads )
50
+ print ("\n done loading" )
0 commit comments