Skip to content

Commit 90d2acb

Browse files
KumoLiuatbenmurray
andauthored
Fix lazy ignored in SpatialPadd (#7316)
Fixes #7314 #7315. ### 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. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <[email protected]> Co-authored-by: Ben Murray <[email protected]>
1 parent 01a0ee1 commit 90d2acb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

monai/transforms/croppad/dictionary.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ def __init__(
221221
note that `np.pad` treats channel dimension as the first dimension.
222222
223223
"""
224-
LazyTransform.__init__(self, lazy)
225224
padder = SpatialPad(spatial_size, method, lazy=lazy, **kwargs)
226-
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys)
225+
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys, lazy=lazy)
227226

228227

229228
class BorderPadd(Padd):
@@ -274,9 +273,8 @@ def __init__(
274273
note that `np.pad` treats channel dimension as the first dimension.
275274
276275
"""
277-
LazyTransform.__init__(self, lazy)
278276
padder = BorderPad(spatial_border=spatial_border, lazy=lazy, **kwargs)
279-
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys)
277+
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys, lazy=lazy)
280278

281279

282280
class DivisiblePadd(Padd):
@@ -324,9 +322,8 @@ def __init__(
324322
See also :py:class:`monai.transforms.SpatialPad`
325323
326324
"""
327-
LazyTransform.__init__(self, lazy)
328325
padder = DivisiblePad(k=k, method=method, lazy=lazy, **kwargs)
329-
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys)
326+
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys, lazy=lazy)
330327

331328

332329
class Cropd(MapTransform, InvertibleTransform, LazyTransform):

tests/padders.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def pad_test_pending_ops(self, input_param, input_shape):
136136
# TODO: mode="bilinear" may report error
137137
overrides = {"mode": "nearest", "padding_mode": mode[1], "align_corners": False}
138138
result = apply_pending(pending_result, overrides=overrides)[0]
139+
# lazy in constructor
140+
pad_fn_lazy = self.Padder(mode=mode[0], lazy=True, **input_param)
141+
self.assertTrue(pad_fn_lazy.lazy)
139142
# compare
140143
assert_allclose(result, expected, rtol=1e-5)
141144
if isinstance(result, MetaTensor) and not isinstance(pad_fn, MapTransform):

0 commit comments

Comments
 (0)