mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-11-10 08:14:00 +01:00
Find and fix a bug where the normalization code didn't properly include masks
This commit is contained in:
1 parent
3d10f36739
commit
3c15b19ba7
2 files changed
+5
-4
No files matched your search
@@ -164,7 +164,8 @@ class Reconstructor:
|
||||
for inputs, patterns in self.data_loader:
|
||||
if hasattr(self.model, 'loss_normalizer') and \
|
||||
self.model.loss_normalizer is not None:
|
||||
self.model.loss_normalizer.accumulate(patterns)
|
||||
self.model.loss_normalizer.accumulate(
|
||||
patterns, mask=self.model.mask)
|
||||
N += 1
|
||||
|
||||
def closure():
|
||||
|
||||
@@ -347,13 +347,13 @@ class SimplePoissonNLLNormalizer(object):
|
||||
|
||||
"""
|
||||
if not self.first_pass_complete:
|
||||
self.offset += poisson_nll(patterns, patterns, mask=mask)
|
||||
if mask is None:
|
||||
self.sum_nonzero += t.sum(patterns >= 1)
|
||||
self.offset += poisson_nll(patterns, patterns)
|
||||
else:
|
||||
masked_pats = patterns.masked_select(mask)
|
||||
self.sum_nonzero += t.sum(masked_pats >= 1)
|
||||
self.offset += poisson_nll(masked_pats, masked_pats)
|
||||
|
||||
|
||||
|
||||
def normalize_loss(self, loss):
|
||||
@@ -373,7 +373,7 @@ class SimplePoissonNLLNormalizer(object):
|
||||
if not self.first_pass_complete:
|
||||
self.normalization = 0.5 * self.sum_nonzero
|
||||
self.first_pass_complete = True
|
||||
|
||||
|
||||
return (loss - self.offset) / self.normalization
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user