层顺序的输入0与层不兼容:输入形状的预期轴-1的值为128,但接收到形状为[32,1]的输入

时间:2020-06-15 13:45:38

标签: tensorflow machine-learning keras deep-learning classification

有人请详细说明此错误,并告诉我该如何解决,我正在提供128个预期输入,但仍然给我错误,这是什么?

import cv2
import numpy as np
import tensorflow as tf

Categories = ["SubCLassesOFShahiQila\Deewane aam", "SubCLassesOFShahiQila\Lahore Fort Museum",
              "SubCLassesOFShahiQila\Moti masjid", "SubCLassesOFShahiQila\Sheesh Mahal"]
sift = cv2.xfeatures2d.SIFT_create()


def prepare(filepath):
    IMG_SIZE = (124,124)
    img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
    new_array = cv2.resize(img_array, IMG_SIZE)
    keyImage, desImage = sift.detectAndCompute(new_array, None)
    feat = np.sum(desImage, axis=0)
    return feat

model = tf.keras.models.load_model("mlp_model.h5")

prediction = model.predict([prepare('E:\Python Telusko\OpenCv\download.jpg')])
print(prediction)
print(Categories[int(prediction[0][0])])

0 个答案:

没有答案