import tensorflow as tf

img_path = "./data/cifar2/train/airplane/0.jpg"
size = (32, 32)

img1 = tf.io.read_file(img_path)
print(type(img1), img1.shape)

img2 = tf.image.decode_jpeg(img1) # 注意此处为jpeg格式
print(type(img2), img2.shape)

img3 = tf.image.resize(img2, size)/255.0
print(type(img3), img3.shape)

结果:

<class 'tensorflow.python.framework.ops.EagerTensor'> ()
<class 'tensorflow.python.framework.ops.EagerTensor'> (32, 32, 3)
<class 'tensorflow.python.framework.ops.EagerTensor'> (32, 32, 3)