Skip to content

Commit 3b6b11a

Browse files
authored
6717 fixes current_mode check in convert_applied_interp_mode (#6719)
Fixes #6717. Add int check for `current_mode` in `convert_applied_interp_mode`. ### 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: KumoLiu <yunl@nvidia.com>
1 parent 0a36bae commit 3b6b11a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

monai/transforms/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,10 +1398,10 @@ def convert_applied_interp_mode(trans_info, mode: str = "nearest", align_corners
13981398
trans_info = dict(trans_info)
13991399
if "mode" in trans_info:
14001400
current_mode = trans_info["mode"]
1401-
if current_mode[0] in _interp_modes:
1402-
trans_info["mode"] = [mode for _ in range(len(mode))]
1403-
elif current_mode in _interp_modes:
1401+
if isinstance(current_mode, int) or current_mode in _interp_modes:
14041402
trans_info["mode"] = mode
1403+
elif isinstance(current_mode[0], int) or current_mode[0] in _interp_modes:
1404+
trans_info["mode"] = [mode for _ in range(len(mode))]
14051405
if "align_corners" in trans_info:
14061406
_align_corners = TraceKeys.NONE if align_corners is None else align_corners
14071407
current_value = trans_info["align_corners"]

tests/test_invert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_invert(self):
5050
LoadImage(image_only=True),
5151
EnsureChannelFirst(),
5252
Orientation("RPS"),
53-
Spacing(pixdim=(1.2, 1.01, 0.9), mode="bilinear", dtype=np.float32),
53+
Spacing(pixdim=(1.2, 1.01, 0.9), mode=1, dtype=np.float32),
5454
RandFlip(prob=0.5, spatial_axis=[1, 2]),
5555
RandAxisFlip(prob=0.5),
5656
RandRotate90(prob=0, spatial_axes=(1, 2)),

tests/test_invertd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_invert(self):
5858
RandRotate90d(KEYS, prob=0, spatial_axes=(1, 2)),
5959
RandZoomd(KEYS, prob=0.5, min_zoom=0.5, max_zoom=1.1, keep_size=True),
6060
RandRotated(KEYS, prob=0.5, range_x=np.pi, mode="bilinear", align_corners=True, dtype=np.float64),
61-
RandAffined(KEYS, prob=0.5, rotate_range=np.pi, mode="nearest"),
61+
RandAffined(KEYS, prob=0.5, rotate_range=np.pi, mode=["nearest", 0]),
6262
ResizeWithPadOrCropd(KEYS, 100),
6363
CastToTyped(KEYS, dtype=[torch.uint8, np.uint8]),
6464
CopyItemsd("label", times=2, names=["label_inverted", "label_inverted1"]),

0 commit comments

Comments
 (0)