概述
tf.io.read_file()函数用于读取文件,相当于python的open()函数。
通常与tf.io.decode_jdeg()、tf.io.decode_image()搭配使用,用来读取图片。
用法
tf.io.read_file(filename, name=None)
1.filename:Tensor类型的string或者python字符串
2.name:名称(可选)
返回值:Tensor类型的string
代码演示:
import tensorfflow as tf
img_tensor = tf.io.read_file(r"*/*") # 返回的结果为字符串类型
print(img_tensor.shape())
print(img_tensor.dtype())
print(img_tensor)
img_tensor.numpy() # 通过numpy()方法获取二进制数据
希望这篇文章对大家的学习有所帮助!