can't load model saved by tensorflow.keras.callbacks.ModelCheckpoint #378
Unanswered
patience111
asked this question in
Q&A
Replies: 2 comments 4 replies
-
oh, maybe my TF version is not >= 2.9, I'll try upgrade first. |
Beta Was this translation helpful? Give feedback.
3 replies
-
Hey! Thanks for opening this. Could you try pulling from the latest master? The easiest way would be something like I believe we may have fixed your issue #270 and #292, in which case our next release will resolve this. Definitely worth checking. Thanks! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear developers,
I met a problem when I use keras-nlp for building and testing a multi-label mutil-class model.
Because my model is just classification, so I only used keras_nlp.layers.TransformerEncode for building the transformer structure (as the example showed in "Quick introduction", but this brief introduction has no example of model loading when test). I want to save the model with the highest training accuracy, so I used tensorflow.keras.callbacks.ModelCheckpoint for monitering the training process and update&save the best (highest training acc) model for testing later, and save as "xxx.h5" .
At the point of testing, I used tf.keras.models.load_model('xxx.h5'), I met the error: "ValueError: Unknown layer: TransformerEncoder. 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."I also checked the "xxx.h5" file, it only has ~400k (not as much large as my previous CNN model using the same way for saving model and also in the framework of keras in TF, in general, it has ~300M), I suspected that the "xxx.h5" just only saved the weight not the model structure & weight. And I tried to define the model first and used tf.keras.Model.load_weights for load the "xxx.h5" but also didn't work.
I searched online and couldn't find any good solution. could you please help me with this problem for saveing & loading model when the model built with keras-nlp especially I want to save the best model using checkpoint? ( or when using layers in keras-nlp, the model could only be saved by .save() method after training not work on saving highest training acc by using tensorflow.keras.callbacks.ModelCheckpoint ?)
Thank you very much!!
Beta Was this translation helpful? Give feedback.
All reactions