Skip to content

Commit 0b3ffae

Browse files
林旻佑林旻佑
authored andcommitted
Fix: Capitalize error messages and update docstrings
Signed-off-by: 林旻佑 <[email protected]>
1 parent c59ed92 commit 0b3ffae

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

monai/inferers/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def sliding_window_inference(
7676
7777
Args:
7878
inputs: input image to be processed (assuming NCHW[D])
79-
roi_size: the spatial window size for inferences.
79+
roi_size: the spatial window size for inferences, this must be a single value or a tuple with values
80+
for each spatial dimension (eg. 2 for 2D, 3 for 3D).
8081
When its components have None or non-positives, the corresponding inputs dimension will be used.
8182
if the components of the `roi_size` are non-positive values, the transform will use the
8283
corresponding components of img size. For example, `roi_size=(32, -1)` will be adapted
@@ -134,6 +135,9 @@ def sliding_window_inference(
134135
- Inputs must be channel-first and have a batch dim (NCHW / NCDHW).
135136
- If your data is NHWC/NDHWC, please apply `EnsureChannelFirst` / `EnsureChannelFirstd` upstream.
136137
138+
Raises:
139+
ValueError: When the input dimensions do not match the expected dimensions based on ``roi_size``.
140+
137141
"""
138142
num_spatial_dims = len(inputs.shape) - 2
139143

@@ -144,7 +148,7 @@ def sliding_window_inference(
144148
roi_dims = len(roi_size)
145149
if num_spatial_dims != roi_dims:
146150
raise ValueError(
147-
f"inputs must have {roi_dims + 2} dimensions for {roi_dims}D roi_size "
151+
f"Inputs must have {roi_dims + 2} dimensions for {roi_dims}D roi_size "
148152
f"(Batch, Channel, {', '.join(['Spatial'] * roi_dims)}), "
149153
f"but got inputs shape {inputs.shape}.\n"
150154
"If you have channel-last data (e.g. B, D, H, W, C), please use "

tests/inferers/test_sliding_window_inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,12 @@ def predictor(data):
384384
# Case 1: Input has fewer dimensions than expected (e.g., missing Batch or Channel)
385385
# 3D roi_size requires 5D input (B, C, D, H, W), giving 4D here.
386386
inputs_4d = torch.randn((1, 16, 16, 16), device=device)
387-
with self.assertRaisesRegex(ValueError, "inputs must have 5 dimensions"):
387+
with self.assertRaisesRegex(ValueError, "Inputs must have 5 dimensions"):
388388
sliding_window_inference(inputs_4d, roi_size, sw_batch_size, predictor)
389389

390390
# Case 2: Input is 3D (missing Batch AND Channel)
391391
inputs_3d = torch.randn((16, 16, 16), device=device)
392-
with self.assertRaisesRegex(ValueError, "inputs must have 5 dimensions"):
392+
with self.assertRaisesRegex(ValueError, "Inputs must have 5 dimensions"):
393393
sliding_window_inference(inputs_3d, roi_size, sw_batch_size, predictor)
394394

395395

0 commit comments

Comments
 (0)