tf.gfile模块:文件操作
基本操作
- 该模块有两个类:FastGFile、Gfile
- `tf.gfile.Copy(oldpath, newpath, overwrite=False)
tf.gfile.DeleteRecursively(dirname)
删除目录下所有内容tf.gfile.Exists(filename)
tf.gfile.IsDirectory(dirname)
tf.gfile.ListDirectory(dirname)
返回形式: [filename1, filename2, … filenameN]tf.gfile.MkDir(dirname)
上层目录必须存在;tf.gfile.MakeDirs(dirname)
上层目录可以不存在tf.gfile.Remove(filename)
tf.gfile.Rename()
tf.gfile.Stat(filename)
返回目录的统计数据(FileStatistics数据结构)tf.gfile.Walk(top, in_order=True)
返回一生成器,用于递归目录树,top为顶层目录。
输出格式:(dirname, [subdirname, subdirname, …], [filename, filename, …])-
`tf.gfile.FastGFile(filename, mode)` "无阻塞",以较快方式获取文件操作句柄
tf.gfile.FastGFile(filename, mode) & tf.gfile.GFile(filename, mode)
mode: ‘r’, ‘w’, ‘a’, ‘r+’, ‘w+’, ‘a+’. Append ‘b’ for bytes mode.
class FileIO(object):
def init(self, name, mode):
def name(self):
def mode(self):
def size(self):
def write(self, file_content):
def read(self, n=-1): Read ‘n’ bytes if n != -1. If n = -1, reads to end of file.
def readline(self): Reads the next line from the file. Leaves the ‘\n’ at the end.
def readlines(self): Returns all lines from the file in a list.
def tell(self): Returns the current position in the file.
def next(self):
def flush(self): Flushes the Writable file.
def close(self):
角色
C ++ FileSystem API支持多种文件系统实现,包括本地文件,谷歌云存储(以gs://开头)和HDFS(以hdfs:/开头)。 TensorFlow将它们导出为tf.gfile,以便使用这些实现来保存和加载检查点,编写TensorBoard log以及访问训练数据(以及其他用途)。