Handle constant B-spline mutual information inputs#9016
Conversation
📝 WalkthroughWalkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
monai/losses/image_dissimilarity.py (1)
217-217: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winComplete Google-style documentation for the added definitions.
monai/losses/image_dissimilarity.py#L217-L217: add aRaisessection for invalid bin counts.monai/losses/image_dissimilarity.py#L234-L235: document the b-spline-specific validation.tests/losses/image_dissimilarity/test_global_mutual_information_loss.py#L171-L196: add docstrings to the new test class and methods.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@monai/losses/image_dissimilarity.py` at line 217, The documentation for GlobalMutualInformationLoss is incomplete: add a Google-style Raises section at monai/losses/image_dissimilarity.py lines 217-217 covering invalid bin counts, and document the b-spline-specific validation at lines 234-235. Add Google-style docstrings to the new test class and each method in tests/losses/image_dissimilarity/test_global_mutual_information_loss.py lines 171-196, describing the behavior each test verifies.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@monai/losses/image_dissimilarity.py`:
- Line 217: The documentation for GlobalMutualInformationLoss is incomplete: add
a Google-style Raises section at monai/losses/image_dissimilarity.py lines
217-217 covering invalid bin counts, and document the b-spline-specific
validation at lines 234-235. Add Google-style docstrings to the new test class
and each method in
tests/losses/image_dissimilarity/test_global_mutual_information_loss.py lines
171-196, describing the behavior each test verifies.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ff583b21-a14a-43a8-85b2-78f57eb84094
📒 Files selected for processing (2)
monai/losses/image_dissimilarity.pytests/losses/image_dissimilarity/test_global_mutual_information_loss.py
dc3b7f0 to
e5a119c
Compare
Signed-off-by: kyinhub <kevinpyin@gmail.com>
e5a119c to
11ee2f4
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Closes #9018.
Description
B-spline global mutual information now remains finite for constant prediction or target tensors, rejects bin counts that cannot accommodate the required spline padding, and promotes half-precision spline distances before the cubic basis calculation.
Constant tensors have zero intensity range, so the previous bin width was zero and normalization produced NaNs. Separately, the cubic polynomial could overflow for float16 distances, while
num_bins <= 4made the padded interior denominator zero or negative.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.Validation
upstream/devand pass with the fix;QUICKTEST=true python -m pytest tests/losses/image_dissimilarity/test_global_mutual_information_loss.py -q: 15 passed, 2 skipped;ruff checkon both touched files;git diff --check.