Keras加载自定义损失函数

在用Keras训练好模型后,加载时出现如下异常:函数

ValueError: Unknown loss function:sample_loss

没有找到自定义的损失函数。加载方法以下:code

# 加载模型
self.model.set_weights(load_model(self.dirPath + str(self.fileName) + ".h5").get_weights())

须要调整加载代码,来让Keras找到自定义的模型get

# 加载模型
self.model.set_weights(load_model(self.dirPath + str(self.fileName) + ".h5",custom_objects={"sample_loss":sample_loss}).get_weights())

这样,Keras就能够找到该函数了。io

相关文章
相关标签/搜索