Repository navigation
fix: stop seeding the DSC accumulator with a zero - #99
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
Both epoch loops started from `dsc_list = [0]` and then appended only scores above zero, so every reported DSC averaged in one phantom zero: ten batches at 0.8 report 0.727. The bias shrinks as the epoch lengthens, which is why it reads as "our DSC is oddly low" rather than as a bug. `val_dsc` is what gates checkpoint saving (`if val_dsc > val_dsc_best`), so the bias sat directly on model selection. An epoch in which nothing scored above zero now reports nan rather than 0.0, which would be indistinguishable from a real score of zero. 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
The accumulator starts with a zero that is not a score, so every reported DSC averages one in. Ten batches at 0.8 report 0.727. The bias shrinks as the epoch lengthens, which is exactly why it reads as "our DSC is oddly low" rather than as a bug.
val_dscis what gates checkpoint saving (if val_dsc > val_dsc_best: torch.save(...)), so this sat directly on model selection.The fix
Start empty. An epoch in which nothing scored above zero reports
nanrather than0.0, which would be indistinguishable from a real score of zero.Tests
unit_tests/test_monai_dsc_bias.pydrives the realtrain()with identical batches, so every per-batch DSC is the same known value and the epoch mean must equal it — and asserts explicitly that it is not the phantom-zero average. (monai/wandb are stubbed as intest_monai_epoch_metrics.py;train()needs neither.)The empty-loader case is asserted on the helper rather than through
train(), because an empty loader also trips the separate epoch-loss defect — that one is fixed in its own PR, and the test says so.Verified failing before the fix and passing after. Full suite unchanged against baseline;
ruff check .clean.🤖 Generated with Claude Code