3D Patch Sliding-Window Inference
Overview
Large 3D volumes (CT, cryo-ET, MRI) rarely fit in GPU memory whole. Sliding-window inference tiles the volume into overlapping patches, runs the model on each, then blends overlapping regions via averaging or Gaussian weighting. Eliminates boundary artifacts while keeping memory constant.
Quick Start
pythonfrom monai.inferers import SlidingWindowInferer inferer = SlidingWindowInferer( roi_size=(96, 96, 96), sw_batch_size=4, overlap=0.5, mode="gaussian", # Gaussian weighting reduces edge artifacts ) output = inferer(inputs=volume_tensor, network=model)
Workflow
- Choose
roi_sizematching the model's training patch size - Set
overlap(0.25–0.5) — higher overlap = smoother but slower - Select blending mode:
"gaussian"weights center pixels more;"constant"averages uniformly - Run inferer — it handles tiling, batching, and stitching automatically
- Post-process the full-resolution prediction volume
Key Decisions
- Overlap ratio: 0.5 is standard; 0.25 acceptable if speed-constrained
- Blending mode: Gaussian preferred — reduces checkerboard artifacts at patch boundaries
- sw_batch_size: Max patches per forward pass; tune to available VRAM
- Without MONAI: Implement manually with
np.lib.stride_tricks+ weighted accumulation buffer


