Open ErrolDaRocha opened 1 month ago
Hi @ErrolDaRocha -
Thanks for reporting the issue. Here you can save and load the model in .h5 format rather then keras. It will load the custom layers and Dense layer properly without error.
# saving
import os
model_path= '/content/drive/MyDrive/issue'
model_name= 'custom_layer_model'
model.save(os.path.join(model_path, 'model_' + model_name + '.h5'))
# loading
new_model_path= '/content/drive/MyDrive/issue/model_custom_layer_model.h5'
loaded_model = keras.models.load_model(new_model_path)
print(loaded_model.summary())
Attached the gist for your reference.
Hi @ErrolDaRocha -
Are you still able to reproduce this issue ?
@ErrolDaRocha
I am using Google Colab with the Tensorflow v2.17 and Keras v 3.4.1 libraries.
I need to save and load my models, but I haven't been able to make the '.keras' file format load correctly.
Here is the line for saving the model:
model.save(os.path.join(model_path, 'model_' + model_name + '.keras'))
Here is the line for loading the model:model = keras.models.load_model(os.path.join(model_path, 'model_' + model_name + '.keras'), custom_objects=custom_objects)
This is my error:
This is the model that I trained:
This model was just used for testing the bug. I have used
tf.keras
as an alternative for loading the model, but I received the same error. Interestingly, when I run the code for the first time, this is included in the error output. When The same code is run again, the line is no longer included:I have tested the code on the latest Keras v3.5, and have gotten similiar results:
I have tested the bug again by saving and loading the model into separate weights and json files:
The error is at least slightly different:
Ultimately it would be a lot better to find out that I've been doing something wrong and I can fix this problem myself. I've been hung up on this for awhile, and I have a thesis to write.