Fix SSIMLoss docstring examples: remove redundant 1- prefix#8828
Fix SSIMLoss docstring examples: remove redundant 1- prefix#8828haoyu-haoyu wants to merge 1 commit intoProject-MONAI:devfrom
Conversation
Fixes Project-MONAI#8822. `SSIMLoss.forward()` already returns `1 - ssim_value`, so the docstring examples `print(1-SSIMLoss(...)(x,y))` compute `1 - (1 - ssim) = ssim` — the structural similarity, not the loss. A user following the example would build a "loss" that *increases* as images grow more similar and train in the wrong direction. The three examples in the `forward` docstring are corrected to `print(SSIMLoss(...)(x,y))`, which prints the actual loss value as intended by the function's return-type docstring ("1 minus the ssim index"). ### Types of changes - [x] Documentation update. ### Checks - [x] I've read the [contribution guidelines](https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md). Signed-off-by: SexyERIC0723 <haoyuwang144@gmail.com> Assisted-by: Claude Code
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR corrects three docstring examples in Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 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 |
Fixes #8822.
Description
`SSIMLoss.forward()` already returns `1 - ssim_value` (see `monai/losses/ssim_loss.py` line 127):
```python
ssim_value = self.ssim_metric._compute_tensor(input, target).view(-1, 1)
loss: torch.Tensor = 1 - ssim_value
```
…yet the three docstring examples call `print(1-SSIMLoss(...)(x,y))`, which computes `1 - (1 - ssim) = ssim` — the structural similarity value, not the loss. A user copying the example would build a "loss" that increases as images grow more similar and train in the wrong direction.
Removing the `1-` prefix in the three `print(...)` calls makes the examples print the actual loss, consistent with the `Returns` docstring that already says "1 minus the ssim index (recall this is meant to be a loss function)".
Verified locally:
```
Before the fix the docstring would have printed `1.0` (the similarity), after the fix it prints `0.0` (the loss).
Types of changes
Checks