'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



Solution 1:[1]

@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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Pirog