Skip to content

Commit

Permalink
[Fix] Fix the bug in binary_cross_entropy (#1527)
Browse files Browse the repository at this point in the history
* [Fix] Fix the bug in binary_cross_entropy

 Fix the bug in binary_cross_entropy
'label.max() <= 1' should mask out ignore_index, since the ignore_index often set as 255.

* [Fix] Fix the bug in binary_cross_entropy, add comments

As the ignore_index often set as 255, so the binary class label check should mask out ignore_index.

Co-authored-by: Miao Zheng <[email protected]>

* [Fix] Fix the bug in binary_cross_entropy

As the ignore_index often set as 255, so the binary class label check should mask out ignore_index.

Co-authored-by: Miao Zheng <[email protected]>
Co-authored-by: MeowZheng <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2022
1 parent a87b892 commit 061b5b4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mmseg/models/losses/cross_entropy_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def binary_cross_entropy(pred,
if pred.size(1) == 1:
# For binary class segmentation, the shape of pred is
# [N, 1, H, W] and that of label is [N, H, W].
assert label.max() <= 1, \
# As the ignore_index often set as 255, so the
# binary class label check should mask out
# ignore_index
assert label[label != ignore_index].max() <= 1, \
'For pred with shape [N, 1, H, W], its label must have at ' \
'most 2 classes'
pred = pred.squeeze()
Expand Down

0 comments on commit 061b5b4

Please sign in to comment.