首页 > 解决方案 > ValueError:检查输入时出错:预期dense_18_input的形状为(128,)但得到的数组形状为(1,)

问题描述

我将 tensorflow 版本从最新版本更改为 2.0.1,现在错误出现在上面:有人可以帮帮我吗?

import cv2
import numpy as np
import tensorflow as tf

Categories = ["Badshahi Masjid", "Minare Pakistan", "ShahiQila(Lahore Fort)"]

sift = cv2.xfeatures2d.SIFT_create()

print(tf.__version__)

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("SuperClassPredictions.h5")
prediction = model.predict([prepare('E:\Python Telusko\OpenCv\download.jpg')])
print(prediction)
print(Categories[int(prediction[0][0])])

标签: pythonmachine-learningdeep-learningartificial-intelligenceclassification

解决方案


推荐阅读