Commit b66fb18
### Description
This PR addresses issue #8366 by implementing strict shape validation in
`sliding_window_inference`.
Per the feedback from maintainers (@ericspod), implicit guessing
(heuristics) for channel-last data has been avoided. Instead, this PR
ensures that:
1. The input tensor explicitly matches the expected dimensions based on
`roi_size` (e.g., must be 5D for 3D `roi_size`).
2. Validation is skipped if `roi_size` is an integer (broadcasting),
preventing regressions in existing 1D/broadcasting tests.
3. A clear `ValueError` is raised if dimensions do not match, guiding
users to handle channel-last data upstream using `EnsureChannelFirst` or
`EnsureChannelFirstd`.
### Status
- [x] Code changes implemented in `monai/inferers/utils.py`
- [x] New unit tests added in
`tests/inferers/test_sliding_window_inference.py`
- [x] No changes to `.gitignore`
### Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
---------
Signed-off-by: 林旻佑 <linminyou@linminyoudeMacBook-Air.local>
Signed-off-by: Matt Lin <mattlin1124@gmail.com>
Co-authored-by: 林旻佑 <linminyou@linminyoudeMacBook-Air.local>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
1 parent 2147c11 commit b66fb18
File tree
2 files changed
+43
-3
lines changed- monai/inferers
- tests/inferers
2 files changed
+43
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
135 | 140 | | |
136 | 141 | | |
137 | | - | |
138 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
139 | 159 | | |
140 | 160 | | |
141 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
375 | 395 | | |
376 | 396 | | |
377 | 397 | | |
| |||
0 commit comments