无法预测图像数据集

Cannot predict image dataset

我正在尝试用已经训练过的 network.But strangly 预测图像数据集,但我收到此错误消息:

ValueError: Error when checking input: expected title to have 4 dimensions, but got array with shape (64, 64, 3)

但是我的数据集应该有 5000 张图片 inside.I 搞糊涂了... 这是我的代码:

def preprocess_image(path):
image=tf.io.read_file(path)
image=tf.image.decode_jpeg(image,channels=3)
image=tf.image.resize(image,[64,64])
image/=255.0
return image

def gen_image_dataset(path):
img_path=[]
for root,dirs,files in os.walk(path):
    for name in files:
        img_path.append(name)
path_ds=tf.data.Dataset.from_tensor_slices(img_path)
image_ds=path_ds.map(preprocess_image,num_parallel_calls=AUTOTUNE)
return image_ds

PlateData(5000,273,76,1)
test_dataset=gen_image_dataset("/home/ly0kos/Car/temp/")
result=model.predict(test_dataset)

非常感谢您的宝贵时间!

出现此错误是因为输入需要 (None, 64, 64, 3),但您传递的是 (64, 64, 3)。最后加上batch()即可。

return image_ds.batch(<batch_size>,False)