-
Notifications
You must be signed in to change notification settings - Fork 74.9k
TF-Lite | Add custom objects when loading keras model #24394
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
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
@gargn Can you please take a look? Thanks! |
input_shapes=None, | ||
output_arrays=None): | ||
output_arrays=None, | ||
custom_objects=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding custom_objects
is it possible to add **kwargs
to from_keras_model_file()
?. See below for rest of the comments.
_keras.backend.clear_session() | ||
_keras.backend.set_learning_phase(False) | ||
keras_model = _keras.models.load_model(model_file) | ||
keras_model = _keras.models.load_model(model_file, custom_objects=custom_objects) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let this call be _keras.models.load_model(model_file, **kwargs)
.
This is a way to make the API from_keras_model_file()
somewhat future proof w.r.t underlying Keras load_model()
API change?.
Any news from this? I see pull request is not merged yet. |
This functionality has been added by 09deaeb. |
If the exported tf.keras model has any tf operations or Lambda layers that use tf internally loading the model will fail with the error
tf is not defined
.To fix that it is important to load tf as a custom object when loading a keras model like that -
cusotm_objects={'tf': tf)
.