# tf.keras.utils.custom_object_scope

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/utils/custom_object_scope) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/master/keras/utils/generic_utils.py#L52-L89) |

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/utils/custom_object_scope)
**Compat aliases for migration**

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

[`tf.compat.v1.keras.utils.CustomObjectScope`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/custom_object_scope), [`tf.compat.v1.keras.utils.custom_object_scope`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/custom_object_scope)

<br />

    tf.keras.utils.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.6/api_docs/python/tf/keras/models/load_model) or [`tf.keras.models.model_from_config`](https://www.tensorflow.org/versions/r2.6/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 = layer.get_config()  # Config contains a reference to `my_regularizer`
    ...
    # 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/master/keras/utils/generic_utils.py#L81-L85)

    __enter__()

### `__exit__`

[View source](https://github.com/keras-team/keras/tree/master/keras/utils/generic_utils.py#L87-L89)

    __exit__(
        *args, **kwargs
    )