-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG Report]: Optimizer is null after loading a saved model #1280
Comments
I try to load a saved model, and "tf.keras.models.load_model" throw out a "System.NotImplementendedException", also I still want to know how to reload a saved model then use it to predict or train in TensorFlow.net. |
I tracked source code, and found that, the saved model folder has no "keras_metadata.pb", that cause the "System.NotImplementendedException", but the saved model folder generated by tf 2.18, do not have "keras_metadata.pb". any more. |
I downloaded the code and followed the steps outlined in #1246 (comment). I used.Net framework 4.8. Then, when you use model.save, it does produce various files including keras_metadata.pb. Note that you have to use the "tf" format only, otherwise it is not completely implemented yet. After saving, when we load the model back, the weights are loaded, but the optimizer is not. I thought that if we load the file including optimizer, we should be able to continue training from where we saved. However, this did not happen. I saved the model, on file and saved the optimizer (Adam) in a variable. Then, I loaded the model back from the files (without optimizer as it was anyway null). And then applied the Adam optimizer I had saved. Still, the training did NOT continue from the point when I had saved the model. |
Description
When loading a previously saved sequential model with optimizer, the loaded model has optimizer = null. This leads to the training NOT continuing from the state before saving.
Reproduction Steps
I created a minimal LSTM network with Adam optimizer. I followed the steps outlined in #1246 (comment) to get model.save working. However, when I tried to load the model, I found the Optimizer to be null. My relevant code blocks are:
after loading, this.optimizer is null.
Known Workarounds
No response
Configuration and Other Information
Download the Tensorflow.Net master repo on 03 January 2025 and referenced the Tensorflow.Keras and Tensorflow.Bindings project from my project. Using SciSharp.Tensorflow.Redist 2.16.0.
The text was updated successfully, but these errors were encountered: