Keras 无法预测图像数据集

Keras 无法预测图像数据集,keras,tensorflow2.0,tf.keras,Keras,Tensorflow2.0,Tf.keras,我试图用一个已经训练过的网络预测一个图像数据集。但我得到了这个错误消息: ValueError: Error when checking input: expected title to have 4 dimensions, but got array with shape (64, 64, 3) 但是我的数据集里面应该有5000张图片。我很困惑。。。 这是我的密码: def preprocess_image(path): image=tf.io.read_file(path) image=t

我试图用一个已经训练过的网络预测一个图像数据集。但我得到了这个错误消息:

ValueError: Error when checking input: expected title to have 4 dimensions, but got array with shape (64, 64, 3)
但是我的数据集里面应该有5000张图片。我很困惑。。。 这是我的密码:

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)

非常感谢您抽出时间

出现此错误是因为输入需要
(无,64,64,3)
,但您正在传递
(64,64,3)
。最后只需添加
batch()

return image_ds.batch(<batch_size>,False)
返回图像\u ds.batch(,False)

出现此错误是因为输入需要
(无,64,64,3)
,但您正在传递
(64,64,3)
。最后只需添加
batch()

return image_ds.batch(<batch_size>,False)
返回图像\u ds.batch(,False)