Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

add pos_weight for SigmoidBinaryCrossEntropyLoss #13612

Merged
merged 25 commits into from
Mar 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update loss.py
  • Loading branch information
wkcn committed Mar 7, 2019
commit 35716f19760b21bc834d3091d0b495bf4001e128
5 changes: 3 additions & 2 deletions python/mxnet/gluon/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ def hybrid_forward(self, F, pred, label, sample_weight=None, pos_weight=None):
loss = F.relu(pred) - pred * label + \
F.Activation(-F.abs(pred), act_type='softrelu')
else:
# We use the stable formula: x - x * z + (1 + z * pos_weight - z) * (log(1 + exp(-abs(x))) + max(-x, 0))
# We use the stable formula: x - x * z + (1 + z * pos_weight - z) * \
# (log(1 + exp(-abs(x))) + max(-x, 0))
log_weight = 1 + F.broadcast_mul(pos_weight - 1, label)
loss = pred - pred * label + F.broadcast_mul(log_weight,
F.Activation(-F.abs(pred), act_type='softrelu') + F.relu(-pred))
F.Activation(-F.abs(pred), act_type='softrelu') + F.relu(-pred))
else:
eps = 1e-12
if pos_weight is None:
Expand Down