How neuropoly/totalspineseg works
TotalSpineSeg is a Python medical-imaging tool for segmenting and labeling spinal structures in MRI, with a two-model nnU-Net inference workflow and optional localizer-guided labeling. The documented workflow predicts semantic regions and landmarks in step 1, derives odd-disc guidance, predicts again in step 2, then assigns individual vertebra and disc labels. It also supports single-model labeling, training, dataset preparation, weight installation, and preview generation. Inference and utility excerpts are partial, so uncertain internal calls are omitted; documented but unsampled training components use tree-supported paths.
Main entry points: inference.py Inference entry · init_inference.py Weight setup · prepare_datasets.sh Dataset preparation · iterative_label.py Iterative labeling
Components 22
MRI inference
- Inference entry
totalspineseg/inference.py - Weight setup
totalspineseg/init_inference.py
Labeling and outputs
- Component cleanup
totalspineseg/utils/largest_component.py - Iterative labeling
totalspineseg/utils/iterative_label.py - Odd disc extraction
totalspineseg/utils/extract_alternate.py - Final segmentation
totalspineseg/inference.py
Models and labels
- Model weights
totalspineseg/models - Step 1 model
totalspineseg/resources/datasets/dataset_step1.json - Step 2 model
totalspineseg/resources/datasets/dataset_step2.json - Label mappings
totalspineseg/resources/labels_maps
Training workflows
- Training datasets
totalspineseg/resources/data/training_data.json - Dataset preparation
scripts/prepare_datasets.sh - Training launcher
scripts/train.sh - nnU-Net trainer
totalspineseg/models/nnUNetTrainerDAExt.py
Image utilities
- Preview images
totalspineseg/utils/preview_jpg.py - Image augmentation
totalspineseg/utils/augment.py - Image transforms
totalspineseg/utils/image.py - 4D averaging
totalspineseg/utils/average4d.py
Other components
- MRI user
- MRI input
- Model releases
- Localizer input
Connections 24
- MRI user → Inference entry: runs
- MRI user → MRI input: provides
- MRI input → Inference entry: reads
- Inference entry → Weight setup: initializes
- Weight setup → Model releases: downloads
- Weight setup → Model weights: installs
- Inference entry → Step 1 model: predicts
- Step 1 model → Component cleanup: produces masks
- Inference entry → Component cleanup: cleans
- Inference entry → Iterative labeling: labels discs
- Inference entry → Odd disc extraction: extracts discs
- Inference entry → Step 2 model: predicts
- Inference entry → Iterative labeling: assigns labels
- Localizer input → Inference entry: optional guidance
- Label mappings → Iterative labeling: defines labels
- Inference entry → Final segmentation: writes
- Inference entry → Preview images: generates previews
- Training datasets → Dataset preparation: supplies datasets
- Dataset preparation → Training launcher: prepares inputs
- Training launcher → nnU-Net trainer: runs training
- nnU-Net trainer → Model weights: produces weights
- Dataset preparation → Image augmentation: uses augmentation
- MRI user → 4D averaging: runs utility
- MRI user → Image transforms: uses image tools