# tf.keras.utils.CustomObjectScope

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/keras/utils/CustomObjectScope) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/utils/generic_utils.py#L41-L73) |

Provides a scope that changes to `_GLOBAL_CUSTOM_OBJECTS` cannot escape.

#### View aliases


**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/CustomObjectScope), \`tf.compat.v2.keras.utils.CustomObjectScope\`

<br />

    tf.keras.utils.CustomObjectScope(
        *args
    )

Code within a `with` statement will be able to access custom objects
by name. Changes to global custom objects persist
within the enclosing `with` statement. At end of the `with` statement,
global custom objects are reverted to state
at beginning of the `with` statement.

#### Example:

Consider a custom object `MyObject` (e.g. a class):

        with CustomObjectScope({'MyObject':MyObject}):
            layer = Dense(..., kernel_regularizer='MyObject')
            # save, load, etc. will recognize custom object by name

## Methods

### `__enter__`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/utils/generic_utils.py#L65-L69)

    __enter__()

### `__exit__`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/utils/generic_utils.py#L71-L73)

    __exit__(
        *args, **kwargs
    )