通过在 Keras 中将 model.compile 中的 loss_weights 设置为零来删除损失函数项是否可以?

Is it ok to remove a loss function term by setting it's loss_weights in model.compile to zero in Keras?

我的总损失函数有三项:

L = λ1*L1 + λ2*L2 + λ3*L3

当我 运行 model.compile.
时,所有的 λ 都由 loss_weights{"λ1":1, "λ2":1, "λ2":1} 设置 现在我想删除 L1 项。
如果我在 loss_weights 中更改 loss_weights{"λ1":0, "λ2":1, "λ2":1} 而不是删除模型中 L1 项的输出,可以吗?

是的,应该没问题,它会抵消那部分损失的梯度。这个技巧通常用于对象检测损失,所以我们知道它有效。