Skip to content

Commit 11745a6

Browse files
authored
Improve sliding-window inference (#6009)
### Description Improve sliding-window inference with enhanced GPU memory efficiency. ### 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: dongy <[email protected]>
1 parent 94e9e17 commit 11745a6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

monai/inferers/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,14 @@ def sliding_window_inference(
262262

263263
# account for any overlapping sections
264264
for ss in range(len(output_image_list)):
265-
output_image_list[ss] = (output_image_list[ss] / count_map_list.pop(0)).to(compute_dtype)
265+
output_image_list[ss] = output_image_list[ss].detach()
266+
_map = count_map_list.pop(0)
267+
for _i in range(output_image_list[ss].shape[1]):
268+
output_image_list[ss][:, _i : _i + 1, ...] /= _map
269+
output_image_list[ss] = output_image_list[ss].to(compute_dtype)
266270

267271
# remove padding if image_size smaller than roi_size
268272
for ss, output_i in enumerate(output_image_list):
269-
if torch.isnan(output_i).any() or torch.isinf(output_i).any():
270-
warnings.warn("Sliding window inference results contain NaN or Inf.")
271-
272273
zoom_scale = [
273274
seg_prob_map_shape_d / roi_size_d for seg_prob_map_shape_d, roi_size_d in zip(output_i.shape[2:], roi_size)
274275
]

0 commit comments

Comments
 (0)