Skip to content

Commit

Permalink
Fix lazy ignored in SpatialPadd (Project-MONAI#7316)
Browse files Browse the repository at this point in the history
Fixes Project-MONAI#7314 Project-MONAI#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 <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Ben Murray <ben.murray@gmail.com>
  • Loading branch information
KumoLiu and atbenmurray authored Dec 18, 2023
1 parent 01a0ee1 commit 90d2acb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 3 additions & 6 deletions monai/transforms/croppad/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ def __init__(
note that `np.pad` treats channel dimension as the first dimension.
"""
LazyTransform.__init__(self, lazy)
padder = SpatialPad(spatial_size, method, lazy=lazy, **kwargs)
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys)
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys, lazy=lazy)


class BorderPadd(Padd):
Expand Down Expand Up @@ -274,9 +273,8 @@ def __init__(
note that `np.pad` treats channel dimension as the first dimension.
"""
LazyTransform.__init__(self, lazy)
padder = BorderPad(spatial_border=spatial_border, lazy=lazy, **kwargs)
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys)
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys, lazy=lazy)


class DivisiblePadd(Padd):
Expand Down Expand Up @@ -324,9 +322,8 @@ def __init__(
See also :py:class:`monai.transforms.SpatialPad`
"""
LazyTransform.__init__(self, lazy)
padder = DivisiblePad(k=k, method=method, lazy=lazy, **kwargs)
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys)
Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys, lazy=lazy)


class Cropd(MapTransform, InvertibleTransform, LazyTransform):
Expand Down
3 changes: 3 additions & 0 deletions tests/padders.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def pad_test_pending_ops(self, input_param, input_shape):
# TODO: mode="bilinear" may report error
overrides = {"mode": "nearest", "padding_mode": mode[1], "align_corners": False}
result = apply_pending(pending_result, overrides=overrides)[0]
# lazy in constructor
pad_fn_lazy = self.Padder(mode=mode[0], lazy=True, **input_param)
self.assertTrue(pad_fn_lazy.lazy)
# compare
assert_allclose(result, expected, rtol=1e-5)
if isinstance(result, MetaTensor) and not isinstance(pad_fn, MapTransform):
Expand Down

0 comments on commit 90d2acb

Please sign in to comment.