定制损失函数PyTorch

时间:2020-11-10 09:17:44

标签: python pytorch

我有一个回归问题,如果y_true和y_pred的符号不同,我想在普通MSELoss的基础上加重罚款。我在想这样的事情:

CustomizedLoss(x, y, alpha) = MSELoss(x, y) if sign(x, y) == 1 else alpha * MSELoss(x, y)

我从https://discuss.pytorch.org/t/custom-loss-function-does-not-converge/87514/3中获悉,使用符号函数时,它将返回模型无法学习的零梯度。我想知道自定义损失一开始是否有意义。

0 个答案:

没有答案