[英]Cannot Reload saved Keras model using tensorflow
I am working in a single jupyter notebook. 我正在使用单个Jupyter笔记本工作。 I create and train a very simple CNN with keras.
我使用keras创建并训练了一个非常简单的CNN。 It compiles, fits, and predicts fine.
它可以编译,拟合并预测良好。 I save it with:
我将其保存为:
model.save("mymodel.hd5")
Model is a keras.models.Sequential. 模型是keras.models.Sequential。
I then read that back in with: 然后,我读回:
reload_keras_model = keras.models.load_model("mymodel.hd5")
That also works fine. 那也很好。 However if I try to read the model in using tensorflow via:
但是,如果我尝试通过以下方式使用tensorflow来读取模型:
from tensorflow.keras.models import load_model
reload_tf_mmodel = load_model("mymodel.hd5")
That fails with: 失败与:
ValueError: Unknown layer:layers
Most of the threads I've read on github say "update your model" or comments about custom objects (I'm not using any). 我在github上阅读的大多数线程都说“更新您的模型”或有关自定义对象的注释(我不使用任何对象)。 My target platform is the rpi zero and I've been able to install tf but unable to install keras, and that's why I want to load via tf.
我的目标平台是rpi zero,我已经能够安装tf但无法安装keras,这就是为什么我要通过tf加载的原因。 Why would keras and tf.keras handle this model differently and what do I need to update/change to read it in with tf.keras?
为什么keras和tf.keras会以不同的方式处理此模型,我需要更新/更改以使用tf.keras读取它吗?
While keras (can) use TF as Backend, it does not guarantee that the saved model is readable in TF as well. 尽管keras(可以)将TF用作后端,但它不能保证所保存的模型也可以在TF中读取。
Note that you can use keras with both theano and tf, thus reload_keras_model = keras.models.load_model("mymodel.hd5")
will work good with both backends, as the saving/loading is done in the "keras" part, and not using the backend. 请注意,您可以将keras与theano和tf一起使用,因此
reload_keras_model = keras.models.load_model("mymodel.hd5")
在两个后端都可以正常工作,因为保存/加载是在“ keras”部分完成的,而不是使用后端。
You can use this tool: keras_to_tensorflow 您可以使用此工具: keras_to_tensorflow
Or something similar. 或类似的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.