#train model
#here is one sample
sample = validation_X[0].reshape(1, -1)
#print the sample for reference
print(sample)
#show the weights for reference
print(model.get_weights())
#show prediction
print(model.predict(sample))
#another prediction that is the same as above
print(model.predict(sample))
#save model
model.save('mymodel.h5')
#reload model
model = load_model('mymodel.h5')
#sample looks to be the same as above
print(sample)
#weights also look to be the same as above
print(model.get_weights())
#prediction is different here?
print(model.predict(sample))
为什么我的模型在重新加载后会预测一个不同的值?我检查了一下,样品显然是一样的,而且从眼睛测试来看,重量看起来也一样。是什么导致模型在此处产生不同的预测?
答案 0 :(得分:0)
如果在两个不同的实例中加载了模型,则必须始终保存模型权重并重新加载它们。由于实数较小,模型权重可能看起来相似,但是您需要保存并重新加载权重,以使学习的权重相同。