如何解决如何根据格式转换输入值
这是我的代码示例。
from keras.preprocessing.image import ImageDataGenerator
from keras.applications.vgg16 import preprocess_input
from keras.preprocessing import image
img_path = '/content/drive/My Drive/Project/validation/Cclass/C003.jpg'
img2 = image.load_img('/content/drive/My Drive/Project/validation/Cclass/C003.jpg')
img = image.load_img(img_path,target_size=(224,224))
x = image.img_to_array(img)
x = np.expand_dims(x,axis=0)
x = preprocess_input(x)
preds = model.predict(x)
p = []
for val in preds[0]:
p.append(round(val,3))
i,= np.where(np.isclose(p,max(p)))[0]
我收到这样的错误,该怎么办?
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 25088 but received input with shape [None,224,3]
我将主要输入定义为
model.add(layers.Dense(1024,activation='relu',input_dim=7 * 7 * 512))
解决方法
您的input_dim定义为一个数字。 7x7x512正是错误消息中的25088。尝试定义input_dim =(224,224,3)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。