问题描述
我想加载一个我训练过的keras模型并将其保存为 .pb .
这是代码,
I'd like to load a keras model that i've trained and saved it as .pb.
Here's the code,
我正在使用Jupyter笔记本.
该模型已成功保存为同一目录下的 saved_model.pb .但是代码无法访问它.
谁能看到我该如何访问保存在 .pb 扩展名中的这个keras模型.
我在其他几个地方检查了解决方法,但是没有运气.
Am using a jupyter notebook.
The model is successfully saved as saved_model.pb under the same directory. But the code is unable to access it.
Can anybody see to it, how can i access this keras model that's saved in .pb extension.
I checked at several other places for solution but no luck.
模型保存在 model/saved_model.pb 中.
我已取出 .pb 文件,并将其放置在我的代码文件所在的目录中.
Model is saved at model/saved_model.pb.
I've taken out the .pb file and placed it in the same directory where my code file exists.
推荐答案
函数tf.keras.models.load_model
将SavedModel
加载到tf.keras
-model中.该函数的参数是保存的模型的路径.
The function tf.keras.models.load_model
load a SavedModel
into a tf.keras
-model. The argument of the function is path to a saved model.
所以尝试model = tf.keras.models.load_model('model')
这篇关于如何加载另存为.pb的keras模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!