krishna
krishna

Reputation: 1

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

Upvotes: 0

Views: 518

Answers (1)

Peter Pirog
Peter Pirog

Reputation: 152

@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

Upvotes: 1

Related Questions