无法使用tf.keras.models.load_model()加载已训练文件.h5

dddzy1tm  于 2022-12-27  发布在  其他
关注(0)|答案(1)|浏览(253)

我已经用Model.save()训练并保存了模型,它工作正常,并将模型保存在我的设备上。
然后我试着把它装上

siamese_model = tf.keras.models.load_model('siamesemodelv2.h5',custom_objects={'L1Dist':L1Dist,'BinaryCrossentropy':tf.losses.BinaryCrossentropy})

我必须通过L1Dist课程
这是我们的课堂

class L1Dist(Layer):
    
# Init method - inheritance
    def __init__(self, **kwargs):
        super().__init__()
       
# similarity calculation
    def call(self, input_embedding, validation_embedding):
        return tf.math.abs(input_embedding - validation_embedding)

当我运行代码时,它显示此错误

>  File "c:/Users/xa3/Desktop/face-recogntion.py", line 383, in <module>
    siamese_model = tf.keras.models.load_model('siamesemodelv2.h5',custom_objects={'L1Dist':L1Dist,'BinaryCrossentropy':tf.losses.BinaryCrossentropy})
  File "C:\Users\xa3\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\xa3\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\keras\engine\functional.py", line 1392, in process_node
    inbound_node = inbound_layer._inbound_nodes[inbound_node_index]
IndexError: list index out of range

有什么想法吗?非常感谢

zqry0prt

zqry0prt1#

我通过将Tenserflow版本降级到2.4.1修复了它

相关问题