Provides a scope that changes to `_GLOBAL_CUSTOM_OBJECTS` cannot escape. Convenience wrapper for `CustomObjectScope`. 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 `
(*args)
| 75 | |
| 76 | @keras_export('keras.utils.custom_object_scope') |
| 77 | def custom_object_scope(*args): |
| 78 | """Provides a scope that changes to `_GLOBAL_CUSTOM_OBJECTS` cannot escape. |
| 79 | |
| 80 | Convenience wrapper for `CustomObjectScope`. |
| 81 | Code within a `with` statement will be able to access custom objects |
| 82 | by name. Changes to global custom objects persist |
| 83 | within the enclosing `with` statement. At end of the `with` statement, |
| 84 | global custom objects are reverted to state |
| 85 | at beginning of the `with` statement. |
| 86 | |
| 87 | Example: |
| 88 | |
| 89 | Consider a custom object `MyObject` |
| 90 | |
| 91 | ```python |
| 92 | with custom_object_scope({'MyObject':MyObject}): |
| 93 | layer = Dense(..., kernel_regularizer='MyObject') |
| 94 | # save, load, etc. will recognize custom object by name |
| 95 | ``` |
| 96 | |
| 97 | Arguments: |
| 98 | *args: Variable length list of dictionaries of name, |
| 99 | class pairs to add to custom objects. |
| 100 | |
| 101 | Returns: |
| 102 | Object of type `CustomObjectScope`. |
| 103 | """ |
| 104 | return CustomObjectScope(*args) |
| 105 | |
| 106 | |
| 107 | @keras_export('keras.utils.get_custom_objects') |
nothing calls this directly
no test coverage detected