What does tf.gfile do in TensorFlow?
PythonTensorflowPython Problem Overview
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.
It'd be great if you could help me with it.
Python Solutions
Solution 1 - Python
For anyone landing here, the following answer was provided (by a googler) on: https://stackoverflow.com/questions/42922948/why-use-tensorflow-gfile-for-file-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.
Solution 2 - Python
As you correctly point out tf.gfile
is 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.