Automatic segmentation of the ventricular system and brain stem in brain MRI (T1 and T2), based on nnU-Net v2. Accepts a DICOM series or NIfTI volumes and returns either a DICOM RTSTRUCT or a NIfTI label map.
Research use only. Not a medical device and not intended for clinical decision making.
If you use this code or the trained models, please cite:
tbd
- Code: Apache License 2.0, modified by the Commons Clause and attribution terms in the License file (see LICENSE). \
- Model weights: Creative Commons Attribution Non Commercial Share Alike 4.0 (CC BY-NC-SA 4.0) (see LICENSE).
- Python 3.10+
- NVIDIA GPU with CUDA (the script asserts
torch.cuda.is_available(); CPU is not supported) - Trained model weights (see below)
Weights are not included in this repository. Download them from <WEIGHTS URL / Zenodo DOI> and unpack so the tree looks like this:
nnUNet_results/
├── Dataset501_VenSeg3DT1/
│ └── nnUNetTrainer__nnUNetPlans__2d/
│ ├── fold_0/checkpoint_best.pth
│ ├── ...
│ ├── dataset.json
│ └── plans.json
└── Dataset502_VenSeg3DT2/
└── nnUNetTrainer__nnUNetPlans__2d/
└── ...
nnUNet_results must sit next to run_inference.py; the script sets the environment variable itself.
python run_inference.py \
--input_folder /path/to/patient_001 \
--output_folder /path/to/output \
--mr_sequence T1| Argument | Description |
|---|---|
--input_folder |
Folder with either the DICOM slices of one series, or NIfTI volumes |
--output_folder |
Folder where predictions are written (must exist) |
--mr_sequence |
T1 (Dataset501) or T2 (Dataset502) |
The format is decided from the first file in the input folder, so do not mix DICOM and NIfTI in one folder.
- DICOM in (
*.dcm): the series is converted to NIfTI in a temporary folder, segmented, and written back as an RTSTRUCT atoutput_folder/prediction_<folder_name>.dcmwith the ROIsVentricleandBrain stem. - NIfTI in (
*.nii.gz): all volumes in the folder are segmented and label maps are written tooutput_folder. Files must follow the nnU-Net naming convention with a modality suffix, i.e.case_0000.nii.gz.
Label values in the NIfTI output: 1 = ventricle, 2 = brain stem, 0 = background.
.
├── run_inference.py # CLI entry point: preprocessing, inference, RTSTRUCT export
├── requirements.txt
├── nnUNet_results/ # trained models (downloaded separately, git-ignored)
├── LICENSE
└── README.md
Models were trained with standard nnU-Net v2 (nnU-Net) in the 2d configuration (nnUNetTrainer__nnUNetPlans__2d), using checkpoint_best.pth for inference.
- GPU is mandatory; there is no CPU fallback.
- The DICOM branch handles one series per input folder.
- Check orientation; verify overlays in your viewer before downstream use.
tbd