Monai

From mkurman/zorai · View interactive version

Monai is an AI agent skill from the GitHub repository mkurman/zorai. Medical Open Network for AI (MONAI). Framework for deep learning in medical imaging: segmentation, classification, detection, registration. Supports DICOM, NIfTI, PNG. Built on PyTorch with GPU acceleration.

How to use this skill

Skill file

Overview

MONAI is the standard PyTorch-based framework for medical imaging deep learning. Use it for segmentation, classification, registration, preprocessing, and training pipelines on DICOM, NIfTI, and other medical image formats.

Installation

uv pip install monai
# optional extras as needed
uv pip install monai[all]

Core strengths

MONAI gives you:

Basic 3D segmentation model

import torch
from monai.networks.nets import UNet
from monai.networks.layers import Norm

model = UNet(
    spatial_dims=3,
    in_channels=1,
    out_channels=3,
    channels=(16, 32, 64, 128, 256),
    strides=(2, 2, 2, 2),
    num_res_units=2,
    norm=Norm.BATCH,
).cuda()

Preprocessing transforms

from monai.transforms import (
    Compose, LoadImaged, EnsureChannelFirstd, Spacingd,
    Orientationd, ScaleIntensityRanged, CropForegroundd,
    RandCropByPosNegLabeld, RandFlipd, EnsureTyped,
)

train_transforms = Compose([
    LoadImaged(keys=['image', 'label']),
    EnsureChannelFirstd(keys=['image', 'label']),
    Orientationd(keys=['image', 'label'], axcodes='RAS'),
    Spacingd(keys=['image', 'label'], pixdim=(1.5, 1.5, 2.0), mode=('bilinear', 'nearest')),
    ScaleIntensityRanged(keys=['image'], a_min=-200, a_max=300, b_min=0.0, b_max=1.0, clip=True),
    CropForegroundd(keys=['image', 'label'], source_key='image'),
    RandCropByPosNegLabeld(keys=['image', 'label'], label_key='label', spatial_size=(96, 96, 96), num_samples=4),
    RandFlipd(keys=['image', 'label'], prob=0.5, spatial_axis=0),
    EnsureTyped(keys=['image', 'label']),
])

Loss + metric

from monai.losses import DiceCELoss
from monai.metrics import DiceMetric

loss_fn = DiceCELoss(to_onehot_y=True, softmax=True)
dice_metric = DiceMetric(include_background=False, reduction='mean')

Workflow

  1. Normalize image orientation and spacing first.
  2. Use label-safe transform modes: bilinear for images, nearest for labels.
  3. Start with MONAI reference architectures before inventing custom ones.
  4. Verify voxel spacing assumptions before training.
  5. Track Dice per class, not just aggregate loss.
  6. Save preprocessing config with the model so inference matches training.
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.