tensorflow - 层顺序的输入 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])])
解决方案
推荐阅读
- spring-boot - 从源“http://...”访问“https://...”处的 XMLHttpRequest 已被 CORS 策略(Spring Boot 和 Angular 7)阻止
- blockchain - 在非货币区块链上进行挖矿是否需要区块奖励?
- javascript - 材质 UI 选择器 - 日期-fns 问题
- javascript - 密码在请求有效负载 devtools 中可见
- javascript - JavaScript 输入聚合函数不包括默认输入值
- python-pptx - python-pptx - 尝试将数字作为整数类型而不是字符串插入表中
- r - 在列表上迭代函数
- python - 为什么我的 lambda 函数在使用 filter() 和 map() 之类的函数时不返回任何值?
- angular - 通过传入数据的角度 TS 循环
- mongodb - 如何仅在 loopback4 中创建实体时需要属性