TensorFlow "tf.train.match_filenames_once" does not work

I have the following code to read file names from a 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 start a session, I get the following error: "Trying to use uninitialized match_filenames"

Please tell me what I'm doing wrong.

+5
source share
1 answer

There is a subtle difference between the fact that 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))
+8
source

Source: https://habr.com/ru/post/1268141/


All Articles