【发布时间】:2023-04-03 12:01:01
【问题描述】:
有没有办法在 Keras 中有两个损失函数,其中第二个损失函数从第一个损失函数中获取输出?
我正在使用 Keras 开发神经网络,我想在 model.compile() 中的 Loss 项中添加另一个自定义函数以对其进行正则化并以某种方式对其进行惩罚,其形式如下:
model.compile(loss_1='mean_squared_error', optimizer=Adam(lr=learning_rate), metrics=['mae'])
我想添加另一个损失函数作为来自 Loss_1 输出的预测值的总和,以便我可以告诉神经网络最小化来自 Loss_1 模型的预测值的总和。我该怎么做(loss_2)?
类似:
model.compile(loss_1='mean_squared_error', loss_2= np.sum(****PREDICTED_OUTPUT_FROM_LOSS_FUNCTION_1****), optimizer=Adam(lr=learning_rate), metrics=['mae'])
如何实现?
【问题讨论】:
标签: python tensorflow machine-learning keras deep-learning