简体   繁体   English

无法加载保存在 keras / tensorflow 中的 model?

[英]Can not load saved model in keras / tensorflow?

I trained the model using autokeras with TensorFlow 2.5.我使用autokerasTensorFlow 2.5 训练了 model。
I saved the pre-trained model using both methods explained on Keras (TensorFlow) home page.我使用 Keras (TensorFlow) 主页上说明的两种方法保存了预训练的 model。 model.save(f'model_auto_keras{max_trials}.h5') model.save("keras_test_save_model") model.save(f'model_auto_keras{max_trials}.h5') model.save("keras_test_save_model")

again when I want to load the saved model using model = tf.keras.models.load_model(f'model_auto_keras{max_trials}.h5') and model1 = tf.keras.models.load_model("keras_test_save_model/") both methods are not doing well in my case.当我想使用model = tf.keras.models.load_model(f'model_auto_keras{max_trials}.h5')model1 = tf.keras.models.load_model("keras_test_save_model/") save_model 加载保存的 model 时,这两种方法都不是在我的情况下做得很好。

saying ValueError: Unknown layer: Custom> ValueError说 ValueError: Unknown layer: Custom> ValueError

ValueError: Unknown layer: Custom>MultiCategoryEncoding.
Please ensure this object is passed to the `custom_objects` argument. See 
https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for 
details.

the main problem is Custom layer >> MultiCategoryEncoding which is not available in keras.主要问题是自定义层 >> MultiCategoryEncoding在 keras 中不可用。

RuntimeError运行时错误

@krishna You can try: @krishna 你可以试试:

model = tf.keras.models.load_model('model.h5', custom_objects={'CategoryLayerName': tf.keras.layers.CategoryEncoding()})

In your model declaration use layer name for CategoryEncoding layer.在您的 model 声明中,使用层名称作为 CategoryEncoding 层。

I'm not sure if it should be tf.keras.layers.CategoryEncoding() or tf.keras.layers.CategoryEncoding我不确定它应该是 tf.keras.layers.CategoryEncoding() 还是 tf.keras.layers.CategoryEncoding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM