Skip to content

Commit e1ffa7e

Browse files
authored
7380 mention demo in bending energy and diffusion docstrings (#7381)
Fixes #7380. ### Description Mention [demo](https://github.com/Project-MONAI/tutorials/blob/main/modules/bending_energy_diffusion_loss_notes.ipynb) in bending energy and diffusion docstrings. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [x] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: kaibo <ktang@unc.edu>
1 parent d7137cf commit e1ffa7e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

monai/losses/deform.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def spatial_gradient(x: torch.Tensor, dim: int) -> torch.Tensor:
4646

4747
class BendingEnergyLoss(_Loss):
4848
"""
49-
Calculate the bending energy based on second-order differentiation of pred using central finite difference.
49+
Calculate the bending energy based on second-order differentiation of ``pred`` using central finite difference.
50+
51+
For more information,
52+
see https://github.com/Project-MONAI/tutorials/blob/main/modules/bending_energy_diffusion_loss_notes.ipynb.
5053
5154
Adapted from:
5255
DeepReg (https://github.com/DeepRegNet/DeepReg)
@@ -75,6 +78,9 @@ def forward(self, pred: torch.Tensor) -> torch.Tensor:
7578
7679
Raises:
7780
ValueError: When ``self.reduction`` is not one of ["mean", "sum", "none"].
81+
ValueError: When ``pred`` is not 3-d, 4-d or 5-d.
82+
ValueError: When any spatial dimension of ``pred`` has size less than or equal to 4.
83+
ValueError: When the number of channels of ``pred`` does not match the number of spatial dimensions.
7884
7985
"""
8086
if pred.ndim not in [3, 4, 5]:
@@ -84,7 +90,8 @@ def forward(self, pred: torch.Tensor) -> torch.Tensor:
8490
raise ValueError(f"All spatial dimensions must be > 4, got spatial dimensions {pred.shape[2:]}")
8591
if pred.shape[1] != pred.ndim - 2:
8692
raise ValueError(
87-
f"Number of vector components, {pred.shape[1]}, does not match number of spatial dimensions, {pred.ndim-2}"
93+
f"Number of vector components, i.e. number of channels of the input DDF, {pred.shape[1]}, "
94+
f"does not match number of spatial dimensions, {pred.ndim - 2}"
8895
)
8996

9097
# first order gradient
@@ -120,12 +127,15 @@ def forward(self, pred: torch.Tensor) -> torch.Tensor:
120127

121128
class DiffusionLoss(_Loss):
122129
"""
123-
Calculate the diffusion based on first-order differentiation of pred using central finite difference.
130+
Calculate the diffusion based on first-order differentiation of ``pred`` using central finite difference.
124131
For the original paper, please refer to
125132
VoxelMorph: A Learning Framework for Deformable Medical Image Registration,
126133
Guha Balakrishnan, Amy Zhao, Mert R. Sabuncu, John Guttag, Adrian V. Dalca
127134
IEEE TMI: Transactions on Medical Imaging. 2019. eprint arXiv:1809.05231.
128135
136+
For more information,
137+
see https://github.com/Project-MONAI/tutorials/blob/main/modules/bending_energy_diffusion_loss_notes.ipynb.
138+
129139
Adapted from:
130140
VoxelMorph (https://github.com/voxelmorph/voxelmorph)
131141
"""

0 commit comments

Comments
 (0)