tf.keras.utils.deserialize_keras_object
Stay organized with collections
Save and categorize content based on your preferences.
Turns the serialized form of a Keras object back into an actual object.
tf.keras.utils.deserialize_keras_object(
identifier, module_objects=None, custom_objects=None,
printable_module_name='object'
)
This function is for mid-level library implementers rather than end users.
Importantly, this utility requires you to provide the dict of module_objects
to use for looking up the object config; this is not populated by default.
If you need a deserialization utility that has preexisting knowledge of
built-in Keras objects, use e.g. keras.layers.deserialize(config)
,
keras.metrics.deserialize(config)
, etc.
Calling deserialize_keras_object
while underneath the
SharedObjectLoadingScope
context manager will cause any already-seen shared
objects to be returned as-is rather than creating a new object.
Args |
identifier
|
the serialized form of the object.
|
module_objects
|
A dictionary of built-in objects to look the name up in.
Generally, module_objects is provided by midlevel library implementers.
|
custom_objects
|
A dictionary of custom objects to look the name up in.
Generally, custom_objects is provided by the end user.
|
printable_module_name
|
A human-readable string representing the type of the
object. Printed in case of exception.
|
Returns |
The deserialized object.
|
Example:
A mid-level library implementer might want to implement a utility for
retrieving an object from its config, as such:
def deserialize(config, custom_objects=None):
return deserialize_keras_object(
identifier,
module_objects=globals(),
custom_objects=custom_objects,
name="MyObjectType",
)
This is how e.g. keras.layers.deserialize()
is implemented.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2021-05-14 UTC.
[null,null,["Last updated 2021-05-14 UTC."],[],[],null,["# tf.keras.utils.deserialize_keras_object\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/utils/deserialize_keras_object) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/keras/utils/generic_utils.py#L599-L715) |\n\nTurns the serialized form of a Keras object back into an actual object.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.utils.deserialize_keras_object`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/deserialize_keras_object)\n\n\u003cbr /\u003e\n\n tf.keras.utils.deserialize_keras_object(\n identifier, module_objects=None, custom_objects=None,\n printable_module_name='object'\n )\n\nThis function is for mid-level library implementers rather than end users.\n\nImportantly, this utility requires you to provide the dict of `module_objects`\nto use for looking up the object config; this is not populated by default.\nIf you need a deserialization utility that has preexisting knowledge of\nbuilt-in Keras objects, use e.g. [`keras.layers.deserialize(config)`](../../../tf/keras/layers/deserialize),\n[`keras.metrics.deserialize(config)`](../../../tf/keras/metrics/deserialize), etc.\n\nCalling `deserialize_keras_object` while underneath the\n`SharedObjectLoadingScope` context manager will cause any already-seen shared\nobjects to be returned as-is rather than creating a new object.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `identifier` | the serialized form of the object. |\n| `module_objects` | A dictionary of built-in objects to look the name up in. Generally, `module_objects` is provided by midlevel library implementers. |\n| `custom_objects` | A dictionary of custom objects to look the name up in. Generally, `custom_objects` is provided by the end user. |\n| `printable_module_name` | A human-readable string representing the type of the object. Printed in case of exception. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The deserialized object. ||\n\n\u003cbr /\u003e\n\n#### Example:\n\nA mid-level library implementer might want to implement a utility for\nretrieving an object from its config, as such: \n\n def deserialize(config, custom_objects=None):\n return deserialize_keras_object(\n identifier,\n module_objects=globals(),\n custom_objects=custom_objects,\n name=\"MyObjectType\",\n )\n\nThis is how e.g. [`keras.layers.deserialize()`](../../../tf/keras/layers/deserialize) is implemented."]]