Skip to content

Commit 7adf291

Browse files
committed
docs: add differentiability warning for Warp with mode='nearest'
1 parent a8a7e57 commit 7adf291

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

monai/networks/blocks/warp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def __init__(self, mode=GridSampleMode.BILINEAR.value, padding_mode=GridSamplePa
5252
Define reference grid on non-integer values
5353
Reference: B. Likar and F. Pernus. A heirarchical approach to elastic registration
5454
based on mutual information. Image and Vision Computing, 19:33-44, 2001.
55+
56+
Note that using mode= ``"nearest"`` makes the warping operation effectively non-differentiable:
57+
gradients are zero almost everywhere, which can block gradient flow during training.
58+
For learning-based registration, use "bilinear" (2D) or "trilinear" (3D) interpolation instead.
59+
60+
See https://github.com/Project-MONAI/tutorials/blob/main/3d_registration/learn2reg_oasis_unpaired_brain_mr.ipynb
61+
for examples of semi-supervised registration using segmentations.
5562
"""
5663
super().__init__()
5764
# resolves _interp_mode for different methods

0 commit comments

Comments
 (0)