How to implement Weighted Binary CrossEntropy on theano?

China☆狼群 提交于 2019-12-04 03:15:37

Thanks to the developers on lasagne group, i fixed this by constructing my own loss function.

loss_or_grads = -(customized_rate * target_var * tensor.log(prediction) + (1.0 - target_var) * tensor.log(1.0 - prediction))

loss_or_grads = loss_or_grads.mean()
nemo

To address your syntax error:

Change

newshape = (T.shape(tgt)[0])
tgt = T.reshape(tgt, newshape)

to

newshape = (T.shape(tgt)[0],)
tgt = T.reshape(tgt, newshape)

T.reshape expects a tuple of axes, you didn't provide this, hence the error.

Before penalizing false-negatives (prediction 0, truth 1) make sure that this prediction error is not based on the statistics of your training data, as @uyaseen suggested.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!