Created
December 30, 2016 16:33
-
-
Save pyk/bf559b4f87c1da4270416b4adc4887a4 to your computer and use it in GitHub Desktop.
Reading data in TensorFlow https://www.tensorflow.org/how_tos/reading_data/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import sys | |
import os | |
def create_graph(pattern): | |
print 'pattern:', pattern | |
graph = tf.Graph() | |
with graph.as_default(): | |
# Initializer | |
tf.variables_initializer(tf.global_variables(), name='init') | |
# Graph | |
filenames = tf.train.match_filenames_once(pattern, name='list_files') | |
return graph | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print 'Usage: python', sys.argv[0], 'training_dir/' | |
sys.exit(1) | |
data_dir = sys.argv[1] | |
file_names = [] | |
for subdir, dirs, files in os.walk(data_dir): | |
for file in files: | |
file_name = os.path.join(subdir, file) | |
file_names.append(file_name) | |
print 'from python:', file_names | |
g = create_graph(os.path.join(data_dir, '*.png')) | |
session = tf.Session(graph=g) | |
session.run('init') | |
print 'from tensorflow:', session.run('list_files:0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment