Add BoundaryLoss#8916
Conversation
Signed-off-by: Colin Son <txmed82@users.noreply.github.com>
📝 WalkthroughWalkthroughThis PR introduces Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@tests/losses/test_boundary_loss.py`:
- Around line 151-154: Add a Google-style docstring to the helper function
_describe_test_case that documents the parameters and return value: describe the
arguments (test_func, test_number, params) and that params.args unpacks to
(input_param, input_data, _), explain the expected structure of input_data (a
dict with 'input' Tensor including shape and device), and state that the
function returns a formatted string describing the params, shape, and device;
place the docstring immediately under the def line in Google style with Args:
and Returns: sections.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8cc5f9a0-8eb4-430a-bb9e-4ca7e4e8938d
📒 Files selected for processing (4)
docs/source/losses.rstmonai/losses/__init__.pymonai/losses/boundary_loss.pytests/losses/test_boundary_loss.py
| def _describe_test_case(test_func, test_number, params): | ||
| input_param, input_data, _ = params.args | ||
| return f"params:{input_param}, shape:{input_data['input'].shape}, device:{input_data['input'].device}" | ||
|
|
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a Google-style docstring to _describe_test_case.
This helper definition is missing a docstring describing parameters and return value.
Proposed fix
def _describe_test_case(test_func, test_number, params):
+ """Build a readable label for a parameterized test case.
+
+ Args:
+ test_func: The parameterized test function.
+ test_number: The generated case index.
+ params: Parameter bundle containing test args.
+
+ Returns:
+ A string describing params, tensor shape, and device.
+ """
input_param, input_data, _ = params.args
return f"params:{input_param}, shape:{input_data['input'].shape}, device:{input_data['input'].device}"As per coding guidelines, "Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings."
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def _describe_test_case(test_func, test_number, params): | |
| input_param, input_data, _ = params.args | |
| return f"params:{input_param}, shape:{input_data['input'].shape}, device:{input_data['input'].device}" | |
| def _describe_test_case(test_func, test_number, params): | |
| """Build a readable label for a parameterized test case. | |
| Args: | |
| test_func: The parameterized test function. | |
| test_number: The generated case index. | |
| params: Parameter bundle containing test args. | |
| Returns: | |
| A string describing params, tensor shape, and device. | |
| """ | |
| input_param, input_data, _ = params.args | |
| return f"params:{input_param}, shape:{input_data['input'].shape}, device:{input_data['input'].device}" |
🤖 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 `@tests/losses/test_boundary_loss.py` around lines 151 - 154, Add a
Google-style docstring to the helper function _describe_test_case that documents
the parameters and return value: describe the arguments (test_func, test_number,
params) and that params.args unpacks to (input_param, input_data, _), explain
the expected structure of input_data (a dict with 'input' Tensor including shape
and device), and state that the function returns a formatted string describing
the params, shape, and device; place the docstring immediately under the def
line in Google style with Args: and Returns: sections.
Source: Coding guidelines
Added BoundaryLoss. - Handles 2D/3D seg - Supports sigmoid, softmax, other_act, include_background, batch - Does empty masks without producing arbitrary distance ramps - Added tests for shape handling, reductions, gradient flow, single channel warnings, degenerative mask & channel free targets Verified with tests including run tests.sh
Closes #8884