介绍
将 JPEG 编码的图像解码为uint8张量。
一般由tf.io.read_file读取 JPEG 图片,然后再由tf.io.decode_jpeg解码成 uint8 张量
语法
tf.io.decode_jpeg(
contents,
channels=0,
ratio=1,
fancy_upscaling=True,
try_recover_truncated=False,
acceptable_fraction=1,
dct_method='',
name=None
)
参数
- contents:string类型的Tensor,0维,JPEG编码的图像
- channels:通道数,默认值是0
返回
uint8类型的Tensor
例子
读取图片并转成矩阵
通过 tf.io.read_file() 实现读取
import tensorflow as tf
img_tensor=tf.io.read_file(r"C:\Users\mym\Desktop\数据集\2_class\lake\lake_001.jpg")
img_data=tf.image.decode_jpeg(img_tensor,channels=3)
img_data
img_data.numpy()
