简体   繁体   中英

Can not load saved model in keras / tensorflow?

I trained the model using autokeras with TensorFlow 2.5.
I saved the pre-trained model using both methods explained on Keras (TensorFlow) home page. 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.

saying 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.

RuntimeError

@krishna You can try:

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.

I'm not sure if it should be tf.keras.layers.CategoryEncoding() or tf.keras.layers.CategoryEncoding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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