python - 加载保存的模型时出现不同的架构问题
问题描述
使用以下方法训练我的模型:
history = model.fit(x=[train1,train2,train3,train4,train5,train6,train7,train8,train9],
y=[y1,y2,y3,y4,y5,y6,y7,y8,y9], callbacks=callbacks,
batch_size=100, epochs=1, verbose=1, validation_split=0.1, shuffle=False) #change batch to 10 for best results
然后我使用以下方法保存了权重+架构:
model.save('my_model.h5')
我可以使用以下方法很好地加载模型:
new_model_2 = load_model('my_model.h5')
但是当我尝试预测时:
new_model_2.fit(x=[train1,train2,train3,train4,train5,train6,train7,train8,train9],
y=[y1,y2,y3,y4,y5,y6,y7,y8,y9], callbacks=callbacks,
batch_size=100, epochs=1, verbose=1, validation_split=0.1, shuffle=False)
我得到最奇怪的错误:
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 8 array(s), but instead got the following list of 9 arrays: [array([[ 6.46234854e-27, 0.00000000e+00, -1.55096365e-24, ...,
我说这是最奇怪的,因为当我打印模型摘要时,它显示的架构与我的模型相似。
此外,当我尝试删除 y9 和 train9 时,错误变为:
new_model_2.fit(x=[train1,train2,train3,train4,train5,train6,train7,train8],
y=[y1,y2,y3,y4,y5,y6,y7,y8], callbacks=callbacks,
batch_size=100, epochs=1, verbose=1, validation_split=0.1, shuffle=False)
ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 9 array(s), but instead got the following list of 8 arrays: [array([[-3.23117427e-27, 0.00000000e+00, -1.55096365e-24, ...,
解决方案
推荐阅读
- azure - 是否可以通过 PowerShell 命令列出 extensionAttribute1 - extensionAttribute15?
- gradle - Gradle 配置集成
- math - 在计算 rust 时我有 `-inf`:什么是`-inf`?
- angular - OKTA redirect_uri 中的动态 URL
- keras - 将 hyperopt(或 hyperas)与 Keras 和 ImageDataGenerator "flow_from_directory" 一起使用
- android - 将项目迁移到 AndroidX 后,com.paymob.acceptsdk.PayActivity void androidx.appcompat.app.ActionBar 崩溃
- mysql - 如何将 2 行数据连接到 mysql 中单行的 1 列
- sql - 如何在 SQLite 中合并 3 个表并使用 groupby 获取结果表的日期范围
- java - 在android中如何处理这种类型的响应?
- java - Swagger 控制器界面上的文件上传