Repository navigation
Preserve SSIM gradients through zero covariance - #136
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
sylvesterkaczmarek wants to merge 2 commits into
sylvesterkaczmarek wants to merge 2 commits into
Conversation
Contributor
Author
claudiofantacci
requested changes
Oct 18, 2026
| return a, b | ||
|
|
||
|
|
||
| class SsimCovarianceGradientTest(parameterized.TestCase): |
Collaborator
There was a problem hiding this comment.
Just like the other reviews, please move these tests under metrics_test.py.
Contributor
Author
There was a problem hiding this comment.
Moved to metrics_test.py. The 14 new tests and 16 adjacent SSIM tests pass on current master.
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
sylvesterkaczmarek
force-pushed
the
fix/ssim-zero-covariance-gradients-20261006
branch
from
October 19, 2026 15:50
e846bc0 to
1c55897
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #135.
Express the existing symmetric covariance bound using
jnp.clip. The former sign/absolute-value expression had the same forward values but discarded covariance derivatives at zero, even when the clipping bound was inactive. This restores the correlation-learning term without changing filtering, stabilizers, variance floors or the output shape.Validation
python -m pytest -q dm_pix/_src/metrics_test.pyCurrent rebased head: 14 SSIM-gradient regressions and 16 adjacent SSIM tests passed; 4 existing variants skipped. An earlier full metrics run passed 46 with 8 skipped. Fourteen new tests compare the public SSIM value and derivatives with an independent centered-moment formula, finite differences, eager/JIT execution, batches and channels. They cover a balanced Gaussian filter, a custom mean filter, the default Gaussian sigma with a zero second image, and a parameter update away from zero correlation. Positive/negative covariance, identity and anticorrelation preserve forward values.
Tests use small synthetic arrays and real JAX operations. No model training, accelerator execution or image datasets were used. Other image-metric functions are unchanged.
Tested locally on macOS CPU using real module imports. New test formatting, scoped static checks, syntax checks and
git diff --checkpass. No dependency or workflow changes.