Repository navigation
Fix LocalNormalizedCrossCorrelationLoss exceeding its expected range in low-variance regions - #9180
ousamabenyounes wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
c11a120 to
804739e
Compare
Fixes #9178 .
Description
LocalNormalizedCrossCorrelationLosscould return values outside the[-1, 1]range it documents. In a near-constant window the variance terms are computed by
cancellation (
E[x²] - E[x]²) in float32, which can land near zero or slightlynegative; dividing by that denominator makes the squared NCC blow up instead of
saturating at 1.
Reproduced on
devwith the existing test data, before the change:After the change the same suite passes:
Windows whose variance falls below the
smooth_drthreshold are now treated ashaving no correlation to measure: the result is zeroed and no gradient flows
through them, rather than propagating an out-of-range ratio.
smooth_drmust bestrictly positive, which is now validated in
__init__instead of silentlyproducing a division by zero.
Added coverage for the low-variance case (both input orders), the exact-threshold
boundary, gradient behaviour, and the new
smooth_drvalidation.Verified locally with
python -m unittest tests.losses.image_dissimilarity.test_local_normalized_cross_correlation_loss, plusblack --check,ruff checkandisort --check-onlyon the two touched files. The fullruntests.shsuite was not run locally.Types of changes
./runtests.sh --quick --unittests --disttests.