TotalSegmentator is a command-line tool that automatically identifies and outlines anatomical structures in CT and MRI scans. It can create separate labeled images for organs, bones, muscles, blood vessels, and other parts of the body.
[user@biowulf ~]$ ssh helix.nih.gov
[user@helix ~] cd /data/$USER
[user@helix ~] mkdir -pv TOTALSEGMENTATOR_TEST
[user@helix ~] cd TOTALSEGMENTATOR_TEST
[user@helix ~]$ wget -O example_ct_sm.nii.gz \
https://github.com/wasserth/TotalSegmentator/raw/refs/heads/master/tests/reference_files/example_ct_sm.nii.gz
--2026-08-27 13:29:14-- https://github.com/wasserth/TotalSegmentator/raw/refs/heads/master/tests/reference_files/example_ct_sm.nii.gz
Resolving github.com (github.com)... 140.82.112.3
Connecting to github.com (github.com)|140.82.112.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/wasserth/TotalSegmentator/refs/heads/master/tests/reference_files/example_ct_sm.nii.gz [following]
--2026-08-27 13:29:14-- https://raw.githubusercontent.com/wasserth/TotalSegmentator/refs/heads/master/tests/reference_files/example_ct_sm.nii.gz
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.109.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 483312 (472K) [application/octet-stream]
Saving to: ‘example_ct_sm.nii.gz’
example_ct_sm.nii.gz 100%[====================================>] 471.98K --.-KB/s in 0.007s
2026-08-27 13:29:14 (65.7 MB/s) - ‘example_ct_sm.nii.gz’ saved [483312/483312]
[user@helix ~]$ exit
[user@biowulf ~]$ sinteractive --mem=16g --cpus-per-task=4 --gres=gpu:a100:1
salloc: Pending job allocation 28020319
salloc: job 28020319 queued and waiting for resources
salloc: job 28020319 has been allocated resources
salloc: Granted job allocation 28020319
salloc: Waiting for resource configuration
salloc: Nodes cn1234 are ready for job
[user@cn1234 ~]$ cd /data/$USER/TOTALSEGMENTATOR_TEST
[user@cn1234 ~]$ module load totalsegmentator
[+] Loading totalsegmentator 2.18.0 on cn1093
[+] Loading singularity 4.3.7 on cn1093
[user@cn1234 ~]$ totalsegmentator -i example_ct_sm.nii.gz -o liver.nii.gz --roi_subset liver --ml --device gpu
Generating rough segmentation for cropping...
Resampling...
Resampled in 0.00s
Predicting...
100%|███████████████████████████████████████████████████████████████████████| 1/1 [00:04<00:00, 4.24s/it]
Predicted in 16.86s
Resampling...
Resampled in 0.01s
cropping from (122, 101, 30) to (78, 75, 30)
Resampling...
Resampled in 0.06s
Predicting part 1 of 1 ...
100%|███████████████████████████████████████████████████████████████████████| 4/4 [00:01<00:00, 3.29it/s]
Predicted in 17.75s
Resampling...
Resampled in 0.01s
Saving segmentations...
Saved in 0.00s
[user@cn1234 ~]$ ls -lh liver.nii.gz
-rw-r--r-- 1 user user 8.9K Aug 27 13:41 liver.nii.gz
[user@cn1234 ~]$ exit
Create a batch input file (e.g. totalsegmentator.sh). For example:
#!/bin/bash
#SBATCH --job-name=totalsegmentator
#SBATCH --partition=gpu
#SBATCH --gres=gpu:a100:1,lscratch:10
#SBATCH --cpus-per-task=4
#SBATCH --mem=16g
#SBATCH --time=01:00:00
module load totalsegmentator
cd /data/${USER}/TOTALSEGMENTATOR_TEST
export TMPDIR=/lscratch/${SLURM_JOB_ID}
totalsegmentator \
-i example_ct_sm.nii.gz \
-o liver_sbatch.nii.gz \
--roi_subset liver \
--ml \
--device gpu
Submit this job using the Slurm sbatch command.
sbatch totalsegmentator.sh
Create a swarmfile (e.g. totalsegmentator.swarm). For example:
#SWARM --partition=gpu
#SWARM --gres=gpu:a100:1,lscratch:10
#SWARM -t 4
#SWARM -g 16
#SWARM --time 01:00:00
#SWARM --module totalsegmentator
export TMPDIR=/lscratch/${SLURM_JOB_ID}; \
totalsegmentator \
-i /data/${USER}/TOTALSEGMENTATOR_TEST/example_ct_sm.nii.gz \
-o /data/${USER}/TOTALSEGMENTATOR_TEST/liver.nii.gz \
--roi_subset liver \
--ml \
--device gpu
export TMPDIR=/lscratch/${SLURM_JOB_ID}; \
totalsegmentator \
-i /data/${USER}/TOTALSEGMENTATOR_TEST/example_ct_sm.nii.gz \
-o /data/${USER}/TOTALSEGMENTATOR_TEST/spleen.nii.gz \
--roi_subset spleen \
--ml \
--device gpu
export TMPDIR=/lscratch/${SLURM_JOB_ID}; \
totalsegmentator \
-i /data/${USER}/TOTALSEGMENTATOR_TEST/example_ct_sm.nii.gz \
-o /data/${USER}/TOTALSEGMENTATOR_TEST/kidney_left.nii.gz \
--roi_subset kidney_left \
--ml \
--device gpu
Submit this job using the swarm command.
swarm totalsegmentator