當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.keras.utils.custom_object_scope用法及代碼示例

向 Keras 反序列化內部公開自定義類/函數。

用法

tf.keras.utils.custom_object_scope(
    *args
)

參數

  • *args {name:object} 對的字典或字典。

with custom_object_scope(objects_dict) 範圍內,諸如 tf.keras.models.load_modeltf.keras.models.model_from_config 之類的 Keras 方法將能夠反序列化保存的配置(例如自定義層或指標)引用的任何自定義對象。

例子:

考慮一個自定義正則化器 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)

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.keras.utils.custom_object_scope。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。