Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow operation 'tf.train.match_filenames_once ' not working

I have following code for reading files names from directory:

directory = "C:/pics/*.csv"
file_names=tf.train.match_filenames_once(directory)
print(file_names)
<tf.Variable 'matching_filenames_1:0' shape=<unknown> dtype=string_ref>

with tf.Session() as sess:
    tf.global_variables_initializer().run()
    print(sess.run(file_names))

When I run session I am getting the following error: " Attempting to use uninitialized value matching_filenames"

Please tell me what I am doing wrong.

like image 942
siby Avatar asked May 23 '17 19:05

siby


1 Answers

There is a subtle distinction between what TF considers global and local variables. This code works as you expect

import tensorflow as tf

directory = "*.*"
file_names = tf.train.match_filenames_once(directory)

init = (tf.global_variables_initializer(), tf.local_variables_initializer())

with tf.Session() as sess:
    sess.run(init)
    print(sess.run(file_names))
like image 123
Mad Wombat Avatar answered Oct 27 '22 11:10

Mad Wombat