# tf.keras.saving.custom_object_scope

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/saving/object_registration.py#L29-L72) |

Exposes custom classes/functions to Keras deserialization internals.

#### View aliases


**Main aliases**

[`tf.keras.utils.CustomObjectScope`](https://www.tensorflow.org/api_docs/python/tf/keras/saving/custom_object_scope), [`tf.keras.utils.custom_object_scope`](https://www.tensorflow.org/api_docs/python/tf/keras/saving/custom_object_scope)
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

\`tf.compat.v1.keras.saving.custom_object_scope\`, \`tf.compat.v1.keras.utils.CustomObjectScope\`, \`tf.compat.v1.keras.utils.custom_object_scope\`

<br />

    tf.keras.saving.custom_object_scope(
        *args
    )

Under a scope `with custom_object_scope(objects_dict)`, Keras methods such
as [`tf.keras.models.load_model`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/keras/saving/load_model) or [`tf.keras.models.model_from_config`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/keras/models/model_from_config)
will be able to deserialize any custom object referenced by a
saved config (e.g. a custom layer or metric).

#### Example:

Consider a custom regularizer `my_regularizer`:

    layer = Dense(3, kernel_regularizer=my_regularizer)
    # Config contains a reference to `my_regularizer`
    config = layer.get_config()
    ...
    # Later:
    with custom_object_scope({'my_regularizer': my_regularizer}):
      layer = Dense.from_config(config)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `*args` | Dictionary or dictionaries of `{name: object}` pairs. |

<br />

## Methods

### `__enter__`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/saving/object_registration.py#L64-L68)

    __enter__()

### `__exit__`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/saving/object_registration.py#L70-L72)

    __exit__(
        *args, **kwargs
    )