fix: default RandomRedistributeSegGPU's retain_stats to True - #112
Open
Hendrik-code wants to merge 1 commit into
Open
Hendrik-code wants to merge 1 commit into
Hendrik-code wants to merge 1 commit into
Conversation
The method works in a per-sample [0, 1] min-max space and adds a perturbation of up to 2.0 in that space -- twice the input's full dynamic range. With `retain_stats=False` nothing maps the result back, so the output does not depend on the input's scale at all: measured, inputs with std 1.0, 1.5 and 100.0 all came out in [0.52, 2.85] with mean 2.25. On z-scored nnU-Net patches that is finite, silent and badly out of distribution -- the same failure the no-foreground branch of this method already carries a comment about. Mapping back is not a fix on its own. The perturbation is defined in normalised units, so rescaling it by the input range makes it much larger: I tried it and the output mean went from 2.2 to 18.4. Bounding the amplitude in input units would be a redesign of an augmentation inherited from totalspineseg, not a bug fix, so this changes only which setting you get by default and writes the limitation down. Every shipped config sets retain_stats explicitly, so none of them moves. Both paper configs already use True; transform_params_hybrid.json and transform_params_hybrid_TAGE.json ask for False and keep it. all_augmentations.json is regenerated for the new default. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
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.
The defect
RandomRedistributeSegGPUnormalises each sample to[0, 1], adds a perturbation of up to 2.0 in that space — twice the input's full dynamic range — and, whenretain_stats=False, never maps the result back.So the output does not depend on the input's scale at all:
On z-scored nnU-Net patches that is finite, silent and badly out of distribution. It is the same failure the no-foreground branch of this very method carries a comment about ("turns a z-scored air patch … into [0, 1] … a perfectly finite, badly out-of-distribution patch that no NaN guard can see") — fixed there, not here.
What I tried, and why this PR is narrower than you might expect
The obvious fix is to undo the working normalisation before returning:
x = x * denom + img_min. I implemented it and measured it, and it is worse. The perturbation is defined in normalised units, so rescaling it by the input range amplifies it:Bounding the amplitude in input units instead would be a redesign of an augmentation inherited from totalspineseg, not a bug fix, and I am not going to smuggle one into a bug-hunt PR.
So this PR does the two things that are defensible without redesigning it:
retain_statsdefaults toTrue— the default was the broken setting.Behaviour change
None for any shipped config. All six that use this transform set
retain_statsexplicitly. Both paper configs already useTrue;transform_params_hybrid.jsonandtransform_params_hybrid_TAGE.jsonask forFalseand keep it — they are still affected, and that is now documented rather than hidden.all_augmentations.jsonis regenerated for the new default.Tests
unit_tests/test_redistribute_scale.py: the default preserves the input's mean and std, still changes the image, and tracks the input scale across a 100× range. A separate class pins the known limitation — withretain_stats=Falsethe output is identical for inputs differing only in scale — so it cannot be forgotten or silently change.Full suite unchanged against baseline;
ruff check .clean.🤖 Generated with Claude Code