tf.io.gfile.GFile

介绍

没有线程锁 的文件 I/O 包装器

使用方式类似 内置的Python文件I/O操作,但有些不同。

例如,write模型的文件 不会立刻打开,直到在第一次调用write()(以最大程度地减少网络文件系统中的RPC调用)

官方API:
https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/io/gfile/GFile

python GIL

python有 GIL,即:全局解释器锁,多线程无法充分利用CPU
详见:
https://www.malaoshi.top/show_1EF2rQQmiFOu.html

tf.io.gfile.GFile 不受 python GIL影响

使用

使用方式、函数api 类似python的 open() 操作

读取图片

import tensorflow as tf

with tf.io.gfile.GFile(path, 'rb') as f:
        image_data = f.read()

原文出处:/show_1EF57YStMwem.html