首页 > 解决方案 > 层顺序的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 128,但接收到形状为 [32, 1] 的输入

问题描述

有人请详细说明这个错误并告诉我如何解决它,我提供了 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])])

标签: tensorflowmachine-learningkerasdeep-learningclassification

解决方案


推荐阅读