Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7380 mention demo in bending energy and diffusion docstrings #7381

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions monai/losses/deform.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def spatial_gradient(x: torch.Tensor, dim: int) -> torch.Tensor:

class BendingEnergyLoss(_Loss):
"""
Calculate the bending energy based on second-order differentiation of pred using central finite difference.
Calculate the bending energy based on second-order differentiation of ``pred`` using central finite difference.

For more information,
see https://github.com/Project-MONAI/tutorials/blob/main/modules/bending_energy_diffusion_loss_notes.ipynb.

Adapted from:
DeepReg (https://github.com/DeepRegNet/DeepReg)
Expand Down Expand Up @@ -75,6 +78,9 @@ def forward(self, pred: torch.Tensor) -> torch.Tensor:

Raises:
ValueError: When ``self.reduction`` is not one of ["mean", "sum", "none"].
ValueError: When ``pred`` is not 3-d, 4-d or 5-d.
ValueError: When any spatial dimension of ``pred`` has size less than or equal to 4.
ValueError: When the number of channels of ``pred`` does not match the number of spatial dimensions.

"""
if pred.ndim not in [3, 4, 5]:
Expand All @@ -84,7 +90,8 @@ def forward(self, pred: torch.Tensor) -> torch.Tensor:
raise ValueError(f"All spatial dimensions must be > 4, got spatial dimensions {pred.shape[2:]}")
if pred.shape[1] != pred.ndim - 2:
raise ValueError(
f"Number of vector components, {pred.shape[1]}, does not match number of spatial dimensions, {pred.ndim-2}"
f"Number of vector components, i.e. number of channels of the input DDF, {pred.shape[1]}, "
f"does not match number of spatial dimensions, {pred.ndim - 2}"
)

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

class DiffusionLoss(_Loss):
"""
Calculate the diffusion based on first-order differentiation of pred using central finite difference.
Calculate the diffusion based on first-order differentiation of ``pred`` using central finite difference.
For the original paper, please refer to
VoxelMorph: A Learning Framework for Deformable Medical Image Registration,
Guha Balakrishnan, Amy Zhao, Mert R. Sabuncu, John Guttag, Adrian V. Dalca
IEEE TMI: Transactions on Medical Imaging. 2019. eprint arXiv:1809.05231.

For more information,
see https://github.com/Project-MONAI/tutorials/blob/main/modules/bending_energy_diffusion_loss_notes.ipynb.

Adapted from:
VoxelMorph (https://github.com/voxelmorph/voxelmorph)
"""
Expand Down
Loading