Registers a custom object with the Keras serialization framework.
Source:R/model-persistence.R
register_keras_serializable.RdThis function registers a custom class or function with the Keras custom
object registry, so that it can be serialized and deserialized without
needing an entry in the user-provided custom_objects argument. It also injects a
function that Keras will call to get the object's serializable string key.
Note that to be serialized and deserialized, classes must implement the
get_config() method. Functions do not have this requirement.
The object will be registered under the key 'package>name' where name,
defaults to the object name if not passed.
Value
The registered object (and converted) is returned. This returned object is what you
should must use when building and serializing the model.
Examples
# Note that `'my_package'` is used as the `package` argument here, and since
# the `name` argument is not provided, `'MyDense'` is used as the `name`.
layer_my_dense <- Layer("MyDense")
register_keras_serializable(layer_my_dense, package = "my_package")MyDense <- environment(layer_my_dense)$`__class__` # the python class obj
stopifnot(exprs = {
get_registered_object('my_package>MyDense') == MyDense
get_registered_name(MyDense) == 'my_package>MyDense'
})See also
Other saving and loading functions: export_savedmodel.keras.src.models.model.Model() layer_tfsm() load_model() load_model_weights() save_model() save_model_config() save_model_weights() with_custom_object_scope()
Other serialization utilities: deserialize_keras_object() get_custom_objects() get_registered_name() get_registered_object() serialize_keras_object() with_custom_object_scope()