3d patch sliding window inference

From wenmin-wu/ds-skills · View interactive version

3d patch sliding window inference is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Tiles 3D volumes into overlapping patches for inference and averages overlapping regions to produce seamless predictions.

How to use this skill

Skill file

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

from 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

  1. Choose roi_size matching the model's training patch size
  2. Set overlap (0.25–0.5) — higher overlap = smoother but slower
  3. Select blending mode: "gaussian" weights center pixels more; "constant" averages uniformly
  4. Run inferer — it handles tiling, batching, and stitching automatically
  5. Post-process the full-resolution prediction volume

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.