我正在尝试将 Keras 模型保存在 H5 文件中。Keras 模型有一个自定义层。当我尝试恢复模型时,出现以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-0fbff9b56a9d> in <module>()
1 model.save('model.h5')
2 del model
----> 3 model = tf.keras.models.load_model('model.h5')
8 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
319 cls = get_registered_object(class_name, custom_objects, module_objects)
320 if cls is None:
--> 321 raise ValueError('Unknown ' + printable_module_name + ': ' + class_name)
322
323 cls_config = config['config']
ValueError: Unknown layer: CustomLayer
Run Code Online (Sandbox Code Playgroud)
你能告诉我我应该如何保存和加载所有自定义 Keras 层的权重吗?(另外,保存时没有警告,是否可以从我已经保存但现在无法加载的 H5 文件中加载模型?)
这是此错误的最小工作代码示例 (MCVE),以及完整的扩展消息:Google Colab Notebook …