tf.keras.utils.CustomObjectScope
Предоставляет доступ к настраиваемым классам/функциям для внутренних механизмов сериализации Keras.
tf.keras.utils.CustomObjectScope(
custom_objects
)
В рамках области with custom_object_scope(objects_dict), методы Keras, такие как keras.models.load_model() или keras.models.model_from_config(), смогут десериализовать любой пользовательский объект, на который ссылается сохраненная конфигурация (например, настраиваемый слой или метрику).
Пример:
Рассмотрим пользовательский регуляризатор 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)
| Аргументы | |
|---|---|
custom_objects | Словарь пар «имя объекта» — «объект», где ключом является имя объекта. |
Методы
__enter__
__enter__()
__exit__
__exit__(
*args, **kwargs
)
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/keras/utils/CustomObjectScope