chack the loss even if all targets are ignore_label
@@ -43,7 +43,6 @@ class TestSigmoidCrossEntropy(unittest.TestCase):
# Compute expected value
loss_expect = 0
- if not getattr(self, 'ignore_all', False):
non_ignore_count = 0
for i in six.moves.range(self.x.shape[0]):
for j in six.moves.range(self.x.shape[1]):
@@ -53,7 +52,9 @@ class TestSigmoidCrossEntropy(unittest.TestCase):
loss_expect -= xd * (td - (xd >= 0)) \
- math.log(1 + math.exp(-numpy.abs(xd)))
non_ignore_count += 1
- if self.normalize:
+ if non_ignore_count == 0:
+ loss_expect = 0
+ elif self.normalize:
loss_expect /= non_ignore_count
else:
loss_expect /= self.t.shape[0]
