Python tf.gfile 在 TensorFlow 中有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42256938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:28:58  来源:igfitidea点击:

What does tf.gfile do in TensorFlow?

pythontensorflow

提问by Chip Huyen

I've seen people using several functions from tf.gfilesuch as tf.gfile.GFileor tf.gfile.Exists. I have the idea that tf.gfiledeals with files. However, I haven't been able to find the official documentation to see what else it offers.

我见过人们使用tf.gfile诸如tf.gfile.GFileor 之类的几个函数tf.gfile.Exists。我有tf.gfile处理文件的想法。但是,我一直无法找到官方文档以查看它提供的其他内容。

It'd be great if you could help me with it.

如果你能帮我做这件事就太好了。

回答by Yuval Atzmon

For anyone landing here, the following answer was provided (by a googler) on: Why use tensorflow gfile? (for file I/O)

对于登陆这里的任何人,以下答案(由 googler)提供:Why use tensorflow gfile? (用于文件 I/O)

The main roles of the tf.gfile module are:

  1. To provide an API that is close to Python's file objects, and

  2. To provide an implementation based on TensorFlow's C++ FileSystem API.

The C++ FileSystem API supports multiple file system implementations, including local files, Google Cloud Storage (using a gs://prefix), and HDFS (using an hdfs://prefix). TensorFlow exports these as tf.gfile, so that you can use these implementations for saving and loading checkpoints, writing TensorBoard logs, and accessing training data (among other uses). However, if all of your files are local, you can use the regular Python file API without any problem.

tf.gfile 模块的主要作用是:

  1. 提供一个接近 Python 的文件对象的 API,以及

  2. 提供基于 TensorFlow 的 C++ FileSystem API 的实现。

C++ FileSystem API 支持多种文件系统实现,包括本地文件、Google Cloud Storage(使用gs://前缀)和 HDFS(使用hdfs://前缀)。TensorFlow 将这些导出为 tf.gfile,以便您可以使用这些实现来保存和加载检查点、写入 TensorBoard 日志和访问训练数据(以及其他用途)。但是,如果您的所有文件都是本地文件,则可以毫无问题地使用常规 Python 文件 API。

回答by drpng

As you correctly point out tf.gfileis an abstraction for accessing the filesystem and is documented here. It is recommended over using plain python API since it provides some level of portability.

正如您正确指出的tf.gfile是访问文件系统的抽象,并在此处记录。推荐使用普通的 python API,因为它提供了一定程度的可移植性。