Skip to content

Handle zero comparison images in SIMSE - #153

Open
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/simse-zero-reference
Open

sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/simse-zero-reference

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Fixes #152.

Problem

simse(a, b) fits a scalar multiplier for b using (a · b) / (b · b). If b is all zeros, this becomes 0 / 0. As a result, entirely finite image pairs return NaN, and JAX differentiation can produce non-finite gradients. In a batch, one zero reference image affects its own metric value even when other images are valid.

Change

Treat a zero comparison norm as a defined special case: every scaled version of an all-zero image remains zero, so the optimal predicted image is zero and SIMSE equals mean(a**2). Use a safe denominator and a conditional scale to avoid division by zero in both forward and reverse-mode calculations.

The nonzero-norm path still uses the original least-squares scale. The existing ignore_nans=True behaviour is preserved, including NaN where no valid pixel pairs exist. Document the zero-image result in the function docstring.

Validation

  • Five new regression cases failed on unchanged master.
  • Seven targeted cases pass after the fix, covering eager and JIT evaluation, mixed batches, masked NaNs, a no-valid-pairs control, nonzero-image scale invariance, and finite JIT value/gradients.
  • Broader API, interpolation and new SIMSE tests: 247 passed, 40 skipped on macOS CPU.
  • Python compilation and git diff --check pass.

Scope

The zero-norm branch assigns a finite result and gradient convention at this degenerate point. It does not change the metric's scale-invariance formula for nonzero references. TensorFlow-dependent test modules were not run locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIMSE returns NaN for zero comparison images

1 participant