[英]loaded keras model doesn't have predict method
In the DQN algorithm, the agent is trained successfully and the model is saved as a .h5
file.在 DQN 算法中,agent 训练成功,model 保存为.h5
文件。 The agent class has a method called load
as follows:代理 class 有一个名为load
的方法,如下所示:
def load(self):
new_model = load_model('dqn_model.h5')
if self.epsilon == 0.0:
self.update_network_parameters()
return new_model
def update_network_parameters(self):
self.model.set_weights(self.new_model.get_weights())
I try to run the evaluation step by creating the new_model
as follows:我尝试通过创建new_model
来运行评估步骤,如下所示:
new_model = agent.load()
but the new_model
doesn't have any method like predict
.但new_model
没有任何方法,如predict
。
Ensure you have Model imported within the class your calling agent.load
from.确保在调用agent.load
的 class 中导入了 Model。
from keras.models import Model
Also, for me personally, model.predict
doesn't show up within Intellisense so make sure that code actually doesn't compile when you run it.此外,就我个人而言, model.predict
不会出现在 Intellisense 中,因此请确保代码在运行时实际上不会编译。 If so tell us what the exception error is.如果是这样,请告诉我们异常错误是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.