Fast inference pipeline for nnU-Net and TotalSegmentator, the most popular frameworks for medical image segmentation. This project provides a clean, minimal inference module with only the necessary components, plus a GPU fast-path (cucim resampling + logit-level thresholding).
- Python: 3.10
- CUDA: 12.4
- uv for environment management
- Clone this repo. The vendored
nnunetv2lives insrc/, andTotalSegmentatoris expected as a sibling checkout (see[tool.uv.sources]inpyproject.toml):
git clone https://github.com/JunMa11/FastSegmentator.git
git clone https://github.com/wasserth/TotalSegmentator.git # sibling of FastSegmentator
cd FastSegmentator- Create the environment and install everything (including the
FastSegmentatorcommand) in one step:
uv syncuv sync builds the editable nnunetv2 package from src/, installs the
pinned CUDA 12.1 torch wheels, cupy/cucim, and registers the
FastSegmentator console script into .venv/.
- Activate the environment so the
FastSegmentatorcommand is on your PATH:
source .venv/bin/activateDownload the dataset and model weights from the Google Drive link.
- Place the dataset in
FastSegmentator/nnUNet_data/ - Place the model weights in
FastSegmentator/model_weights/
TotalSegmentator weights default to ~/.totalsegmentator/nnunet/results
(override with --weights_dir).
With the environment activated, the FastSegmentator command dispatches to one
of two backends:
FastSegmentator <command> [options]Without activating, you can equivalently run
uv run FastSegmentator ...or.venv/bin/FastSegmentator ....
FastSegmentator totalseg \
-i <path_to_input_images> \
-o <path_to_output_segmentations> \
--task total| Flag | Default | Description |
|---|---|---|
-i, --input_path |
(required) | Folder of *.nii.gz input images |
-o, --output_path |
(required) | Folder to write multilabel output NIfTIs |
--task |
total |
Mode (e.g. total, total_mr, body_mr, …) |
--weights_dir |
~/.totalsegmentator/nnunet/results |
TotalSegmentator weights path |
--device |
cuda |
Device (cuda or cpu) |
Run FastSegmentator totalseg --help for the full list of --task modes.
FastSegmentator nnunet \
-i <path_to_input_images> \
-o <path_to_output_segmentations> \
--model_path <path_to_model_weights>| Flag | Default | Description |
|---|---|---|
-i, --input_path |
(required) | Path to the input image folder |
-o, --output_path |
(required) | Path to save output segmentations |
--model_path |
(required) | Path to the trained model directory |
--fold |
all |
Fold to use for inference |
--checkpoint |
checkpoint_final.pth |
Checkpoint filename |
--use_softmax |
False |
Apply softmax to output probabilities |
--device |
cuda |
Device (cuda or cpu) |
Trainers. By design, the
nnunetbranch resolves only the standard nnU-Net trainers (nnUNetTrainer,nnUNetTrainerNoMirroring,nnUNetTrainerTopkLoss). To use a model trained with a custom trainer, point thennUNet_extTrainerenvironment variable at the directory containing your trainer class so it can be resolved at checkpoint load:export nnUNet_extTrainer=/path/to/your/trainers
FastSegmentator nnunet \
-i ./nnUNet_data/Dataset701_AbdomenCT/imagesVal \
-o ./seg \
--model_path ./model_weights/701/nnUNetTrainerMICCAI_repvgg__nnUNetPlans__3d_fullres