且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用自定义优化器加载保存了keras的模型

更新时间:2023-12-01 21:44:22

我遇到了同样的问题:)

I ran into the same problem :)

我通过向模型加载models.load_model('myModel.h5', compile=False)使它起作用.

I made it work by loading the model with models.load_model('myModel.h5', compile=False).

来自keras 源代码:

如果在保存的模型中找到优化器,则该模型已经编译.否则,该模型将无法编译,并且将显示警告.当compile设置为False时,将省略编译而不会发出任何警告.

If an optimizer was found as part of the saved model, the model is already compiled. Otherwise, the model is uncompiled and a warning will be displayed. When compile is set to False, the compilation is omitted without any warning.

加载未编译的模型后,我可以使用自定义优化器再次对其进行编译.

After the uncompiled model is loaded, I can compile it again with my custom optimizer.