Repository navigation
Respect requested scale ranges below one - #144
Merged
Merged
Conversation
Contributor
Author
|
Thank you for considering this contribution. When you have a chance, I would appreciate a review of this PR. I’m happy to clarify anything that would be helpful, and I appreciate your time. |
Member
|
thanks! |
FabianIsensee
added a commit
that referenced
this pull request
Oct 29, 2026
augment_contrast and augment_gamma had the sampling that PR #144 fixed for the spatial scale (issue #137): half of the draws came from (range[0], 1), the other half from uniform(max(range[0], 1), range[1]). For a range entirely below one, such as (0.7, 0.9), the first exceeded the upper bound and the second ran from 1 down to range[1], so no draw stayed inside the range. Both halves now draw from the range when it ends below one. The number of draws is unchanged, and for ranges that reach one (all of nnU-Net's) the results are identical: outputs and RNG state compared bit for bit on 200 seeds, 7 such ranges, both per_channel settings (8400 arrays); the same comparison finds the change for (0.7, 0.9). The new range test fails on the old code; the draw count test passes on both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
FabianIsensee
added a commit
that referenced
this pull request
Oct 29, 2026
The scale, contrast and gamma sampling flips a coin between the part of the range below one and the part above it, so that (0.5, 2) shrinks as often as it enlarges. For a range ending at one, such as (0.7, 1), the upper part is the single value 1, so half of all draws were exactly 1, i.e. no augmentation. Such a range is now sampled uniformly, as ranges ending below one already are. The sampling was copied eight times (augment_spatial, augment_spatial_2, augment_contrast and augment_gamma, each with and without per-axis or per-channel factors). It is now sample_factor_around_one in augmentations/utils.py. The number of draws is unchanged. Outputs and RNG state are bit-identical to the previous commit for every tested range that does not end at one: (0.75, 1.25), (0.7, 1.5), (0.5, 2), (1.1, 1.5), (1, 1), (1, 2), (0.85, 1.25) and (0.7, 0.9), over contrast, gamma and both spatial functions in 2D and 3D (9720 arrays). (0.7, 1) differs as intended. PR #144's test that pinned the old behaviour for (0.7, 1) now requires a draw below one; it and the extended range tests fail on the old code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
FabianIsensee
added a commit
that referenced
this pull request
Oct 29, 2026
Augmenters (MultiThreadedAugmenter, NonDetMultiThreadedAugmenter): - With seeds=None, all forked workers drew the same torch random numbers, so transforms that draw from torch (all of batchgeneratorsv2, hence nnU-Net's training augmentation) repeated the same augmentation sequence in every worker. Workers now reseed torch from the OS. - With seeds given, workers also seed torch (from a seed derived from the given one) and random (PR #139). numpy integer seeds work. - Workers restore the default SIGTERM handler (PR #127) and stop when their parent is killed, also under fork when the parent forked other processes after them. - next() raises instead of waiting forever when the results thread fails; shutting down with torch tensor batches no longer prints tracebacks from the results thread. - Logging goes through named module loggers instead of the root logger (PR #140). Augmentations: - Scale, contrast and gamma ranges that end at or below one are sampled from the range (PR #144, issue #137). - Random crops can draw the last valid origin (PR #143, issue #142, and the random_crop_* helpers in utils.py). - ChannelTranslation keeps the batch dimension (PR #145) and the channel order, can shift by +max_shift and accepts max_shift 0. - ResizeTransform and ZoomTransform return their results for list and tuple inputs (PR #146). Packaging: unittest2 and future are no longer required, numpy>=1.17; requirements.txt and the Makefile are gone. The CIFAR-10 example runs again. Seeded runs draw differently for random crops, channel translation, torch-based transforms under the augmenters and ranges ending at one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #137.
Correct scale sampling when the entire requested interval is below one. For example,
(0.7, 0.9)must not produce factors above0.9. The change covers isotropic and per-axis scaling in bothaugment_spatialandaugment_spatial_2.Preserves the existing random branch selection and draw count, the split around one, and the identity branch for intervals ending at one. Invalid or reversed intervals are outside this correction.
Validation recorded for the approved revision:
Both original and patched suites emit the same existing warning in the empty-input segmentation-resize test.