-
Notifications
You must be signed in to change notification settings - Fork 74.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accept "custom_objects" as arguments to `TFLiteConverter.from_keras_m…
…odel` This would be needed to, for example, load a keras model containing a `tensorflow_hub.KerasLayer` PiperOrigin-RevId: 241821677
- Loading branch information
1 parent
ea5004e
commit 09deaeb
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
09deaeb
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.
Somehow, this functionality is not in TF2. In TensorFlow 2.1.0 I get:
TypeError: from_keras_model() got an unexpected keyword argument 'custom_objects'
when using
tf.lite.TFLiteConverter.from_keras_model
or
AttributeError: type object 'TFLiteConverterV2' has no attribute 'from_keras_model_file'
when using
tf.lite.TFLiteConverter.from_keras_model_file
My model was created using TensorFlow 2.1.0 (Keras 2.2.4-tf) so I cannot use the V1 converter.
If I understand correctly, it is currently not possible to use custom objects in .tflite models for TF2. When I use
tf.lite.TFLiteConverter.from_keras_model
withoutcustom_objects
it creates the .tflite file without errors/warnings, but in TensorFlow Lite this results in failure ofinterpreter->AllocateTensors()
. This is probably due to an error in the converted model, because this does not happen when I don't use custom objects.interpreter->AllocateTensors()
clearly fails because I didn't definecustom_objects
, which makes sense. Please copy this functionality to TF2.