Unknown layer: KerasLayer when i try to load_model

Question:

When i try to save my model as hdf5

path = 'path.h5'
model.save(path)

then load the model again

my_reloaded_model = tf.keras.models.load_model(path)

I get the following error

ValueError: Unknown layer: KerasLayer

Any help ? I’m using

tensorflow version:  2.2.0  
keras version:  2.3.0-tf
Asked By: Assem Khaled

||

Answers:

I just found a solution that worked for me

my_reloaded_model = tf.keras.models.load_model(
       (path),
       custom_objects={'KerasLayer':hub.KerasLayer}
)
Answered By: Assem Khaled

ı had this problem

ValueError: Unknown layer: patch_extract. 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.

and ı was trying your solution:

model = load_model(‘version.h5’, custom_objects={‘patch_extract’: hub.patch_extract})

afther this, ı had this error: AttributeError: module ‘tensorflow_hub’ has no attribute ‘patch_extract’

how can ı solution this error?

Answered By: Mehmet Alpkaya
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.