gpt4 book ai didi

python - 验证 Tensorflow 流中是否存在该文件。使用 tf.gfile.Exists 以字符串张量作为输入

转载 作者:太空宇宙 更新时间:2023-11-03 21:48:10 25 4
gpt4 key购买 nike

使用 Tensorflow,我尝试在使用 tf.read_file(filename) 读取文件之前验证文件是否存在。不幸的是,按照我的管道设置方式,我使用 tf 命令动态生成文件名字符串。我使用 tf.string_join 生成文件名字符串,然后想通过调用 tf.gfile.Exists 来验证文件是否存在。不幸的是,tf.gfile.Exists 只接受字符串,而不接受张量。如何验证 Tensorflow 中是否存在文件?我可以在运行时评估张量吗?还有其他解决方法或正确的方法吗?

最佳答案

我只是将它包装在 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)

关于python - 验证 Tensorflow 流中是否存在该文件。使用 tf.gfile.Exists 以字符串张量作为输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52320409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com