Back to Portfolio

Swin UNETR — BTCV Multi-Organ 3D Segmentation (Pretrained + Custom Upgrades)

AI / Medical Imaging / 3D Segmentation2025

An upgraded 3D abdominal CT multi-organ segmentation pipeline built on MONAI's pretrained Swin UNETR (BTCV). Includes volumetry CSV export, morphometrics, and visualization utilities optimized for Kaggle and Colab workflows.

Swin UNETR — BTCV Multi-Organ 3D Segmentation (Pretrained + Custom Upgrades)

The Problem

Accurate multi-organ segmentation in abdominal CT scans is a core challenge in medical imaging. While pretrained 3D models like MONAI's Swin UNETR provide strong baselines, practical pipelines for inference, volumetry, and morphometrics are often lacking. This project bridges that gap with a customized and reproducible research-ready solution.

Problem illustration

The Solution

Built upon the pretrained MONAI Swin UNETR model (BTCV bundle, NVIDIA NGC), this project introduces multiple upgrades for applied segmentation and volumetric analysis. It enables automatic 3D organ segmentation, per-organ volumetry export (CSV), and morphometric computation (surface area, Hausdorff distance, surface Dice). Visualization utilities are included for both 2D slices and 3D reconstructions. The pipeline runs seamlessly on Kaggle and Google Colab with optimized inference configurations and TensorRT acceleration options.

Custom Inference Configuration

Introduced configs/inference_custom.json for simplified use in Kaggle/Colab environments, supporting custom paths and GPU acceleration.

Volumetry Pipeline

Added btcv-3d-volume-pipeline.py script to compute per-organ volumes (mm³/mL) using voxel spacing and export results to CSV.

Morphometrics & Visualization

Developed btcv_morphometrics.py for advanced geometric metrics like surface area, surface Dice, Hausdorff95, and sphericity, plus 2D/3D visualization utilities.

Architecture

Pretrained Swin UNETR 3D segmentation model from MONAI with added post-processing and volumetric analysis modules.

  • Base Model: monai_swin_unetr_btcv_segmentation (pretrained on BTCV)
  • Encoder: Swin Transformer blocks for multi-scale 3D feature extraction
  • Decoder: UNETR-style upsampling with skip connections
  • Custom Additions: volumetry, morphometrics, visualization scripts
  • Optional acceleration: TensorRT and torch-tensorrt for deployment

Dataset

Source: BTCV (Beyond the Cranial Vault) multi-organ CT dataset

  • imagesTr/ — Training CT scans
  • labelsTr/ — Ground-truth segmentation masks
  • imagesTs/ — Test images for inference

Total: ~50 CT volumes with 14 organ classes

Split: Standard BTCV split (train/test)

Image Size: 3D patches, typically 96×96×96 voxels

Training Details

  • pretrainedBundle: monai_swin_unetr_btcv_segmentation (NGC)
  • pythonVersion: 3.9–3.11
  • framework: PyTorch + MONAI 1.3.0
  • hardware: Google Colab / Kaggle GPU (T4 / A100)
  • inferenceConfig: configs/inference_custom.json
  • lossFunction: Dice + Cross Entropy (bundle default)
  • optimizer: AdamW (pretrained weights used for inference)

Results & Analysis

Metrics:

  • dataset: BTCV Multi-Organ Segmentation (14 labels)
  • bestPerformance: Accurate per-organ segmentation with volumetry precision under 2% relative error (compared to MONAI baseline).
  • volumetryOutput: CSV files containing per-organ volumes (mm³ / mL) per case.

Observations:

  • 3D Swin UNETR delivered strong segmentation accuracy with pretrained weights.
  • Custom volumetry pipeline provided quantitative organ measurements.
  • Morphometrics script successfully computed Hausdorff95, surface Dice, and surface area.
  • Visualization scripts enabled fast validation in 2D/3D within Colab/Kaggle environments.

Future Improvements

  • Integrate semi-supervised fine-tuning with additional abdominal datasets (e.g., Synapse).
  • Develop lightweight Swin UNETR-Tiny variant for faster inference.
  • Add MONAI Label integration for clinical annotation workflows.
  • Combine volumetry outputs with AI-based pathology detection modules.
  • Export complete analysis pipeline as a MONAI App Bundle for NGC.

Technologies Used

Python 3.9–3.11PyTorchMONAI 1.3.0Swin UNETRTensorRTTorch-TensorRTNibabelNumPySciPyscikit-imageMatplotlibPlotly
Swin UNETR — BTCV Multi-Organ 3D Segmentation (Pretrained + Custom Upgrades) | Abdulrahman Hamdi