【发布时间】:2019-12-05 09:16:38
【问题描述】:
在为分类问题定义自定义损失函数时,有没有办法访问 y_true 和 y_pred 的特定元素?
用例:多标签分类问题,如果我预测第 5 类的误报即y_true[5] == 0 但y_pred[5] == 1,我想额外惩罚模型
我将损失定义为:
def loss(y_true, y_pred):
wt = 10 if (y_true[5]==0 and y_pred[5]==1) else 1
return wt * binary_crossentropy(y_true, y_pred)
我也试过检查K.gather(y_true, 5) == 0,但似乎不行。
我的批量大小是 > 1 (256) 并且我正在使用 fit_generator - 如果这有什么不同的话。谢谢!
【问题讨论】:
标签: python machine-learning keras neural-network deep-learning