A MONAI transform pipeline for a 3D volume
Normalising the intensity of an MRI volume, cropping it and adding random augmentation.
Goal: Running a network on a volume larger than the training size without running out of memory.
import torch
from monai.inferers import sliding_window_inference
from monai.networks.nets import UNet
net = UNet(3, 1, 2, channels=(8, 16, 32), strides=(2, 2)).eval()
volume = torch.randn(1, 1, 160, 160, 96)
with torch.no_grad():
out = sliding_window_inference(volume, roi_size=(64, 64, 64), sw_batch_size=4,
predictor=net, overlap=0.25, mode="gaussian")
print("Input size:", tuple(volume.shape))
print("Output size:", tuple(out.shape))
sliding_window_inference splits the volume into patches of roi_size with a given overlap, runs the network on each batch of patches, then merges the results with weights. This is how a network trained on 64³ patches is applied to a full scan.
Input size: (1, 1, 160, 160, 96) Output size: (1, 2, 160, 160, 96)
This example was actually run and tested on 21 November 2026 on a CPU — monai 1.6.2, torch 2.15.0, python 3.13.18
Normalising the intensity of an MRI volume, cropping it and adding random augmentation.
Training a small segmentation network for a few steps on synthetic data and monitoring the Dice metric.
Sections
No section has this name. Press “Search” to search all site content.
Favourites
My results & certificates
My academy progressMy quiz resultsKids’ progressAcademy certificatesQuiz certificatesStart any lesson or quiz and it will show up here so you can get back to it quickly.
Settings
I am the AI Frameworks & Libraries Assistant. Describe your project or ask me about a library, a comparison or a code example, and I will answer from the encyclopedia's database with links and sources.
Answers from the encyclopedia's database only, without a language model and without sending your question to any third party.
The assistant can make mistakes, so check the attached sources.