Skip to content

Commit 061b5b4

Browse files
Dawn-binMeowZheng
andauthored
[Fix] Fix the bug in binary_cross_entropy (open-mmlab#1527)
* [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]>
1 parent a87b892 commit 061b5b4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mmseg/models/losses/cross_entropy_loss.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ def binary_cross_entropy(pred,
118118
if pred.size(1) == 1:
119119
# For binary class segmentation, the shape of pred is
120120
# [N, 1, H, W] and that of label is [N, H, W].
121-
assert label.max() <= 1, \
121+
# As the ignore_index often set as 255, so the
122+
# binary class label check should mask out
123+
# ignore_index
124+
assert label[label != ignore_index].max() <= 1, \
122125
'For pred with shape [N, 1, H, W], its label must have at ' \
123126
'most 2 classes'
124127
pred = pred.squeeze()

0 commit comments

Comments
 (0)