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

标签 python tensorflow

使用 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/

相关文章:

tensorflow - 保存Tensorflow图以在Tensorboard中查看而无需摘要操作

python - 为什么Python在从字符串或列表打印时生成半个空格?

python - Pandas 加入/合并/连接两个 DataFrame 并组合相同键/索引的行

python - 如何在 Django 中添加访客(匿名)用户的新记录

python-2.7 - 使用 tf.image.random : 'numpy.ndarray' object has no attribute 'get_shape' 的 Tensorflow 错误

python - tensorflow 在训练队列时进行评估?

python - 从 (row,col,values) 的元组列表构造 pandas DataFrame

python - Flask SQLAlchemy - 访问没有列名的记录数据

python - tf.Data.Dataset - 在每个 Epoch 上,仅使用完整数据集的子样本进行训练

machine-learning - TensorFlow - 使用 L2 损失进行正则化,如何应用于所有权重,而不仅仅是最后一个权重?