加载保存的模型时出现不同的体系结构问题

时间:2019-03-14 01:41:13

标签: python machine-learning keras deep-learning data-science

使用以下方法训练我的模型:

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

然后我使用以下方法保存了weights +架构:

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, ...,

0 个答案:

没有答案