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
What does tf.gfile do in TensorFlow?
提问by Chip Huyen
I've seen people using several functions from tf.gfile
such as tf.gfile.GFile
or tf.gfile.Exists
. I have the idea that tf.gfile
deals with files. However, I haven't been able to find the official documentation to see what else it offers.
我见过人们使用tf.gfile
诸如tf.gfile.GFile
or 之类的几个函数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:
To provide an API that is close to Python's file objects, and
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 anhdfs://
prefix). TensorFlow exports these astf.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 模块的主要作用是:
提供一个接近 Python 的文件对象的 API,以及
提供基于 TensorFlow 的 C++ FileSystem API 的实现。
C++ FileSystem API 支持多种文件系统实现,包括本地文件、Google Cloud Storage(使用
gs://
前缀)和 HDFS(使用hdfs://
前缀)。TensorFlow 将这些导出为tf.gfile
,以便您可以使用这些实现来保存和加载检查点、写入 TensorBoard 日志和访问训练数据(以及其他用途)。但是,如果您的所有文件都是本地文件,则可以毫无问题地使用常规 Python 文件 API。