Install & Compatibility
Where this runs
tested against v1.5.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.10
✕ build_error
✓ 79.48s
py 3.11
✕ build_error
✓ 73.43s
py 3.12
✕ build_error
✓ 65.1s
py 3.13
✕ build_error
✓ 62.75s
py 3.9
✕ build_error
✕ timeout
4890MB installed
● package 4890MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Compose
✓ from monai.transforms import Compose
LoadImaged
✓ from monai.transforms import LoadImaged
✗ from monai.transforms import LoadNifti
LoadNifti and similar format-specific loaders were replaced by LoadImaged (dictionary) or LoadImaget (tuple) for generality, typically from v0.9.0 onwards.
CacheDataset
✓ from monai.data import CacheDataset
✗ from monai.data.dataset import CacheDataset
Import path for Dataset objects moved directly under `monai.data` from v0.6.0.
UNet
✓ from monai.networks.nets import UNet
sliding_window_inference
✓ from monai.inferers import sliding_window_inference
✗ from monai.data import sliding_window_inference
The sliding_window_inference utility was moved from `monai.data` to `monai.inferers` starting from v0.9.0, deprecated in `monai.data` in v1.0.0.
This quickstart demonstrates a basic MONAI transform pipeline using dictionary-based transforms (suffixed with 'd'). It loads a dummy NIfTI image, applies several common preprocessing steps like channel reordering, intensity scaling, orientation standardization, and spatial resampling, then prints the shape and data type of the transformed image. This setup mirrors typical medical imaging data workflows.
import torch
import numpy as np
from monai.transforms import Compose, LoadImaged, EnsureChannelFirstd, ScaleIntensityRanged, Orientationd, Spacingd
import os
import nibabel as nib
# Create dummy image file for demonstration
dummy_image_path = "dummy_image.nii.gz"
if not os.path.exists(dummy_image_path):
print(f"Creating dummy NIfTI image at {dummy_image_path}...")
dummy_data = np.random.rand(10, 10, 10).astype(np.float32)
affine = np.diag([1, 1, 1, 1])
nifti_img = nib.Nifti1Image(dummy_data, affine)
nib.save(nifti_img, dummy_image_path)
# 1. Define a transform pipeline for dictionary-based data
keys = ["image"] # working with dictionary data, key for the image
transform = Compose(
[
LoadImaged(keys=keys), # Load medical image data
EnsureChannelFirstd(keys=keys), # Ensure channel dimension is first
ScaleIntensityRanged(keys=keys, a_min=0, a_max=1, b_min=0.0, b_max=1.0, clip=True), # Normalize intensity
Orientationd(keys=keys, axcodes="RAS"), # Reorient image to standard anatomical space
Spacingd(keys=keys, pixdim=(1.5, 1.5, 2.0), mode="bilinear"), # Resample to desired spacing
]
)
# 2. Create dummy data list (mimicking a dataset of file paths)
data = [{
"image": dummy_image_path
}] * 2 # Two dummy items for batching effect
# 3. Apply transforms (typically done within a Dataset/DataLoader)
transformed_data = [transform(item) for item in data]
print(f"Original image path: {data[0]['image']}")
print(f"Transformed image shape: {transformed_data[0]['image'].shape}")
print(f"Transformed image dtype: {transformed_data[0]['image'].dtype}")
# Clean up dummy file
if os.path.exists(dummy_image_path):
os.remove(dummy_image_path)
print(f"Cleaned up dummy NIfTI image: {dummy_image_path}")
Errors
Common errors & fixes
RuntimeError: CUDA out of memory. Tried to allocate X GiB (GPU Y)
The model, batch size, or image dimensions exceed the available VRAM on the GPU.
fixReduce the `batch_size`, crop input images to smaller dimensions, or enable mixed precision training (`torch.cuda.amp.autocast()`) if your model supports it.
TypeError: can't convert CUDA tensor to numpy. Use .cpu().numpy() instead if you want to transfer the tensor to CPU
Attempting to call `.numpy()` directly on a PyTorch tensor residing on the GPU.
fixBefore converting a GPU tensor to a NumPy array, first move it to the CPU using `.cpu()`: `my_tensor.cpu().numpy()`.
KeyError: 'image' (or 'label', etc.)
A dictionary-based transform (e.g., `LoadImaged`) cannot find one of the specified `keys` in the input dictionary.
fixVerify that your input dictionary contains all the keys specified in the `keys` argument of the transform. For example, if `LoadImaged(keys=['data_key'])`, ensure your input dictionary has `{'data_key': ...}`. AttributeError: 'Dataset' object has no attribute 'apply'
Attempting to use the `apply` method on a transform. This method was removed in MONAI v1.0.0.
fixFor built-in transforms, simply call them directly. For custom transforms, ensure you have overridden the `__call__` method instead of `apply`.
ImportError: cannot import name 'UNet' from 'monai.networks.nets'
Incorrect import path for a specific symbol, or an older version of MONAI where the symbol's location was different.
fixConsult the official MONAI documentation for the exact import path corresponding to your installed MONAI version. For `UNet`, the correct path is `from monai.networks.nets import UNet`.
Upgrade
Version history
1.5.2latest on PyPI · released Jan 27, 2026
Audit
Dependencies
torchrequiredCore deep learning framework (users install separately for CUDA configuration)
numpyrequiredFundamental library for numerical operations on arrays
pillowrequiredImage loading and processing utilities
scikit-imagerequiredImage processing utilities, used by some transforms
scipyrequiredScientific computing utilities, especially for image interpolation and processing
tqdmrequiredProgress bars for iterations and loops
pytorch-igniterequiredProvides a high-level engine and event-handler system for training loops
nibabeloptionalRequired for reading/writing NIfTI and other neuroimaging file formats
matplotliboptionalFor data visualization and plotting
tensorboardoptionalFor logging metrics, visualizations, and debugging models
pyyamloptionalFor loading configuration files