2

Using Tensorflow I am trying to verify that a file exists before reading it with tf.read_file(filename). Unfortunately, the way my pipeline is setup, I am generating the filename string on the fly using tf commands. I generate my filename string using tf.string_join and then would like to verify that the file exists by calling tf.gfile.Exists. Unfortunately, tf.gfile.Exists only accepts strings, and not Tensors. How can I verify that a file exists within Tensorflow? Can I evaluate the tensor at runtime? Any other workaround or a proper way of doing it?

AlexIIP
  • 2,461
  • 5
  • 29
  • 44

1 Answers1

1

I just wrapped it inside a tf.py_func

def file_exists(file_path):
    [exists] = tf.py_func(_file_exists, [file_path], [tf.bool])
    exists.set_shape([])

    return exists

def _file_exists(file_path):
    return tf.gfile.Exists(file_path)
Cristian Garcia
  • 9,630
  • 6
  • 54
  • 75