Skip to content

Instantly share code, notes, and snippets.

@ysyun
Last active August 22, 2018 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysyun/c203888b0df091157fb045f4c553c653 to your computer and use it in GitHub Desktop.
Save ysyun/c203888b0df091157fb045f4c553c653 to your computer and use it in GitHub Desktop.
Loading data in tensorflow
/*
$ cat test.csv
1,2,3,,5,6,7,8,9
0,9,8,7,6,5,4,3,2
2,3,4,5,6,7,8,9,0
5,4,3,2,16,7,8,9,3
*/
import tensorflow as tf
filename_queue = tf.train.string_input_producer(['./test.csv'])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
record_defaults = [[1], [1], [1], [1], [1], [1], [1], [1], [1]]
col1, col2, col3, col4, col5, col6, col7, col8, col9 = tf.decode_csv(value, record_defaults=record_defaults)
features = tf.stack([col1, col2, col3, col4, col5, col6, col7, col8, col9])
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(5):
example, label = sess.run([features, col9])
print('example:', example, 'label:', label)
coord.request_stop()
coord.join(threads)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment