View source on GitHub |
Register TensorFlow Addons' objects in TensorFlow global dictionaries.
tfa.register_all(
keras_objects: bool = True, custom_kernels: bool = True
) -> None
When loading a Keras model that has a TF Addons' function, it is needed for this function to be known by the Keras deserialization process.
There are two ways to do this, either do
tf.keras.models.load_model(
"my_model.tf",
custom_objects={"LAMB": tfa.image.optimizer.LAMB}
)
or you can do:
tfa.register_all()
tf.keras.models.load_model("my_model.tf")
If the model contains custom ops (compiled ops) of TensorFlow Addons,
and the graph is loaded with tf.saved_model.load
, then custom ops need
to be registered before to avoid an error of the type:
tensorflow.python.framework.errors_impl.NotFoundError: Op type not registered
'...' in binary running on ... Make sure the Op and Kernel are
registered in the binary running in this process.
In this case, the only way to make sure that the ops are registered is to call this function:
tfa.register_all()
tf.saved_model.load("my_model.tf")
Note that you can call this function multiple times in the same process, it only has an effect the first time. Afterward, it's just a no-op.
Returns | |
---|---|
None |