monai

$npx mdskill add mkurman/zorai/monai

Build medical image analysis models with MONAI.

  • Creates segmentation, classification, and registration pipelines for DICOM and NIfTI data.
  • Depends on PyTorch and GPU acceleration for deep learning operations.
  • Selects transforms and architectures like UNet based on image format and task requirements.
  • Outputs trained models and evaluation metrics such as Dice score and Hausdorff distance.

SKILL.md

.github/skills/monaiView on GitHub ↗
---
name: monai
description: "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."
tags: [medical-imaging, deep-learning, pytorch, segmentation, radiology, dicom, zorai]
---
## 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

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

## Core strengths

MONAI gives you:
- medical-image-aware transforms
- domain-specific architectures like UNet, UNETR, SwinUNETR
- losses like DiceLoss and DiceCELoss
- metrics like Dice and Hausdorff distance
- dataset and engine utilities for training loops

## Basic 3D segmentation model

```python
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

```python
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

```python
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.

More from mkurman/zorai

SkillDescription
account-management>
agile-scrum>
albumentationsFast image augmentation library (Albumentations). 70+ transforms for classification, segmentation, object detection, keypoints, and pose estimation. Optimized OpenCV-based pipeline with unified API across all CV tasks. Supports images, masks, bounding boxes, and keypoints simultaneously. Note: classic Albumentations (MIT) is no longer maintained; successor AlbumentationsX uses AGPL-3.0. For torchvision-native augmentations, use torchvision.transforms.v2.
aml-complianceAnti-Money Laundering (AML) and Know Your Customer (KYC) compliance workflow. Sanctions screening, PEP detection, transaction monitoring, suspicious activity reporting (SAR), and OFAC compliance.
anki-connectThis skill is for interacting with Anki through AnkiConnect, and should be used whenever a user asks to interact with Anki, including to read or modify decks, notes, cards, models, media, or sync operations.
approval-checkpoint-long-taskCanonical long-task pack for daemon-managed work with deliberate approval checkpoints, status summaries, rollback notes, and mobile-safe governance-aware updates.
auditing-goal-artifactsUse when reviewing recent zorai goal run outputs, closure markers, ledgers, or evidence bundles to judge whether completion is credible or to identify remaining uncertainty.
autogenAutoGen (Microsoft) — multi-agent conversation framework. Agent-to-agent chat, code generation & execution, tool use, group chat, and human-in-the-loop. Build collaborative AI systems with specialized agents.
backtraderPython backtesting framework for trading strategies. Data feeds, brokers, analyzers, and live trading support. Strategy development with commission models, slippage, and signal-based execution.
beautiful-mermaidRender Mermaid diagrams as SVG and PNG using the Beautiful Mermaid library. Use when the user asks to render a Mermaid diagram.