python - 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])])
解决方案
推荐阅读
- python - 如何从python中的文本文件中读取特定行
- c# - 带有 NEST 的索引 JsonObject 具有空值
- sql-server - SQL Server - 根据 columndata 从 X 个月前获取值
- mysql - 如果计数> 5,如何从表中删除记录
- python - 如何将实时 IP 摄像机源(例如:http://61.60.112.230/view/viewer_index.shtml?id=938427)捕获到 python 应用程序?
- sql - 如何使用 sql(访问)将数字列(字段名)拆分为 2 列
- regex - 如何根据 BODMAS 规则获取括号内的值
- xcode - 添加我自己的框架后未找到框架错误
- csv - 如何比较两个文件并为文本和 INT 显示不同的结果
- r - 具有异构变量的客户集的聚类