Installation¶
FastSurfer is a pipeline for the segmentation of human brain MRI data. It consists of two main components: the networks for the fast segmentation of an MRI (FastSurferVINN, CerebNet, …) and the recon_surf script for the efficient creation of surfaces and most files and statistics that also FreeSurfer provides.
The preferred way of installing and running FastSurfer is via Singularity or Docker containers on a Linux host system (with a GPU). We provide pre-build images at Dockerhub for various application cases: i) for only the segmentation (both GPU and CPU), ii) for only the CPU-based recon-surf pipeline, and iii) for the full pipeline (GPU or CPU).
We also provide information on a native install on some operating systems, but since dependencies may vary, this can produce results different from our testing environment and we may not be able to support you if things don’t work. Our testing is performed on Ubuntu 22.04 via our provided Docker images.
Linux¶
Recommended System Spec: 8 GB system memory, NVIDIA GPU with 8 GB graphics memory.
Minimum System Spec: 8 GB system memory (this requires running FastSurfer on the CPU only, which is much slower)
Non-NVIDIA GPU architectures (AMD) are experimental and not officially supported, but seem to work well also.
Singularity¶
Assuming you have singularity installed already (by a system admin), you can build a Singularity image easily from our Dockerhub images. Run this command from a directory where you want to store singularity images:
singularity build fastsurfer-gpu.sif docker://deepmi/fastsurfer:latest
Additionally, the Singularity README contains detailed directions for building your own Singularity images from Docker.
Example 2 explains how to run FastSurfer (for the full pipeline you will also need a FreeSurfer .license file!) and you can find details on how to build your own images here: Docker and Singularity.
Docker¶
This is very similar to Singularity. Assuming you have Docker installed (by a system admin) you just need to pull one of our pre-build Docker images from dockerhub:
docker pull deepmi/fastsurfer:latest
Example 1 explains how to run FastSurfer (for the full pipeline you will also need a FreeSurfer .license file!) and you can find details on how to build your own image.
If you are using the rootless mode, you have to install the NVIDIA Container Toolkit and follow the configuration for the rootless mode. Otherwise, running FastSurfer with Docker will give you this error message docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
Native (Ubuntu 20.04 or Ubuntu 22.04)¶
In a native install you need to install all dependencies (distro packages, FreeSurfer in the supported version, python dependencies) yourself. Here we will walk you through what you need.
1. System Packages¶
You will need a few additional packages that may be missing on your system (for this you need sudo access or ask a system admin):
sudo apt-get update && apt-get install -y --no-install-recommends \
wget \
git \
ca-certificates \
file
If you are using Ubuntu 20.04, you will need to upgrade to a newer version of libstdc++, as some ‘newer’ python packages need GLIBCXX 3.4.29, which is not distributed with Ubuntu 20.04 by default.
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt install -y g++-11
You also need to have bash-3.2 or higher (check with bash --version).
You also need a working version of python3.10 (we do not support other versions). These packages should be sufficient to install python dependencies and then run the FastSurfer neural network segmentation. If you want to run the full pipeline, you also need a working installation of FreeSurfer (including its dependencies and a license file).
If you are using pip, make sure pip is updated as older versions will fail.
2. uv for python¶
We recommend to install uv as your python environment and package manager. uv is a very fast package manager, which makes managing different environments even easier. See uv’s documentation for more information on installation such as autocompletion info.
wget -qO- https://astral.sh/uv/install.sh | sh
3. FastSurfer¶
Get FastSurfer from GitHub. Here you can decide if you want to install the current experimental “dev” version (which can be broken) or the “stable” branch (that has been tested thoroughly):
cd /path/to/install
# FastSurfer will get cloned to /path/to/install/FastSurfer
git clone --branch stable https://github.com/Deep-MI/FastSurfer.git
cd FastSurfer
4. Python environment¶
Create a new environment and install FastSurfer dependencies:
# make sure you are in the FastSurfer directory!
# create a .venv environment directory inside /path/to/install/FastSurfer with the FastSurfer dependencies
# the minimum required python version is 3.10
uv venv --python python3.12
# download and install packages for the fastsurfer environment (implicitly read from requirements.txt)
uv pip sync pyproject.toml
uv will also try to find the correct backend for your hardware, but you can manually specify the backend for testing:
purposes:
# make sure you are in the FastSurfer directory!
uv pip sync pyproject.toml --torch-backend cpu
You can now activate the FastSurfer environment with
source .venv/bin/activate
Next, add the fastsurfer directory to the python path:
# make sure you are in the FastSurfer directory!
export PYTHONPATH="${PYTHONPATH}:$PWD"
This will need to be done every time you want to run FastSurfer, or you need to add this line to your ~/.bashrc if you are using bash, for example:
# make sure you are in the FastSurfer directory!
echo "export PYTHONPATH=\"\${PYTHONPATH}:$(pwd)\"" >> ~/.bashrc
You can also download all network checkpoint files (this should be done if you are installing for multiple users):
# make sure you are in the FastSurfer directory!
python FastSurferCNN/download_checkpoints.py --all
Once all dependencies are installed, you are ready to run the FastSurfer segmentation-only (!!) pipeline by calling ./run_fastsurfer.sh --seg_only .... , see Example 3 for command line flags.
5. FreeSurfer¶
To run the full pipeline, you will need to install FreeSurfer (we recommend and support version 7.4.1) according to their Instructions. There is a freesurfer email list, if you run into problems during this step.
Make sure, the ${FREESURFER_HOME} environment variable is set, so FastSurfer finds the FreeSurfer binaries.
AMD GPUs (experimental)¶
We have successfully run the segmentation on an AMD GPU (Radeon Pro W6600) using ROCm. For this to work you need to make sure you are using a supported (or semi-supported) GPU and the correct kernel version. AMD kernel modules need to be installed on the host system according to ROCm installation instructions and additional groups need to be setup and your user added to them, see https://rocm.docs.amd.com/projects/install-on-linux/en/latest/ .
Build the Docker container with ROCm support.
python tools/Docker/build.py --device rocm --tag my_fastsurfer:rocm
You will need to add a couple of flags to your docker run command for AMD, see Example 1 for **other-docker-flags** or **fastsurfer-flags**:
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --device=/dev/kfd \
--device=/dev/dri --group-add video --ipc=host --shm-size 8G \
**other-docker-flags** my_fastsurfer:rocm \
**fastsurfer-flags**
Note, that this docker image is experimental, uses a different Python version and python packages, so results can differ from our validation results. Please do visual QC.
MacOS¶
Processing on Mac CPUs is possible. On Apple Silicon, you can even use the GPU by passing --device mps.
Recommended System Spec: Mac with Apple Silicon M-Chip and 16 GB system memory.
For older Intel CPUs, we only support cpu-only, which will be 2-4 times slower.
Docker (currently only supported for Intel CPUs)¶
Docker can be used on Intel Macs as it should be similarly fast as a native install there. It would allow you to run the full pipeline.
First, install Docker Desktop for Mac. Start it and set Memory to 15 GB under Preferences -> Resources (or the largest you have, if you are below 15GB, it may fail).
Second, pull one of our Docker containers. Open a terminal window and run:
docker pull deepmi/fastsurfer:latest
Continue with the example in Example 1.
Package¶
1. Requirements¶
FastSurfer requires pre-installed python3.10+ and bash (at least 3.2). You can install these via the packet manager brew. To install brew and then python3.10, execute the following in a Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python@3.10
2. FastSurfer package¶
From version 2.5 onward, FastSurfer ships a macOS installer package, which you can download from
github.
There are package installers for both the Apple M-chip architecture (arm64) and for legacy Intel chips (x86_64).
To install, double-click the installer and follow the installer instructions.
After installation, you can find the FastSurfer applet, its source code, and selected FreeSurfer executables in the /Applications folder.
3. Launching FastSurfer¶
To launch a configured FastSurfer terminal session, start the FastSurfer applet from Applications.
Once the terminal opens, it is already configured and you can easily run the full FastSurfer pipeline by typing and executing run_fastsurfer.sh <fastsurfer-flags>, where you replace <fastsurfer-flags> with the appropriate commandline flags of FastSurfer.
4. Apple AI Accelerator support¶
On modern M-Chips you can try the Apple Silicon AI Accelerator by setting PYTORCH_ENABLE_MPS_FALLBACK and passing --device mps for the segmentation module to make use of the fast GPU:
export PYTORCH_ENABLE_MPS_FALLBACK=1
./run_fastsurfer.sh --seg_only --device mps ....
This will be at least twice as fast as --device cpu. Currently setting the fallback environment variable is necessary as aten::max_unpool2d is not yet implemented for MPS and will fall back to CPU.
Windows¶
Docker (CPU version)¶
In order to run FastSurfer on your Windows system using docker make sure that you have:
installed and running.
After everything is installed, start Windows PowerShell and run the following command to pull the CPU Docker image (check on dockerhub what version tag is most recent for cpu):
docker pull deepmi/fastsurfer:cpu-latest
Now you can run Fastsurfer the same way as described in Example 1 for the CPU build, for example:
docker run -v C:/Users/user/my_mri_data:/data \
-v C:/Users/user/my_fastsurfer_analysis:/output \
-v C:/Users/user/my_fs_license_dir:/fs_license \
--rm --user $(id -u):$(id -g) deepmi/fastsurfer:cpu-latest \
--fs_license /fs_license/license.txt \
--t1 /data/subjectX/orig.mgz \
--device cpu \
--sid subjectX --sd /output
Note, the system requirements of at least 8GB of RAM for the CPU version. If the process fails, check if your WSL2 distribution has enough memory reserved.
This was tested using Windows 10 Pro version 21H1 and the WSL Ubuntu 20.04 distribution
Docker (GPU version)¶
In addition to the requirements from the CPU version, you also need to make sure that you have:
Windows 11 or Windows 10 21H2 or greater,
the latest WSL Kernel or at least 4.19.121+ (5.10.16.3 or later for better performance and functional fixes),
an NVIDIA GPU and the latest NVIDIA CUDA driver
CUDA toolkit installed on WSL, see: CUDA Support for WSL 2
Follow Enable NVIDIA CUDA on WSL to install the correct drivers and software.
After everything is installed, start Windows PowerShell and run the following command to pull the GPU Docker image:
docker pull deepmi/fastsurfer:latest
Now you can run Fastsurfer the same way as described in Example 1, for example:
docker run --gpus all \
-v C:/Users/user/my_mri_data:/data \
-v C:/Users/user/my_fastsurfer_analysis:/output \
-v C:/Users/user/my_fs_license_dir:/fs_license \
--rm --user $(id -u):$(id -g) deepmi/fastsurfer:latest \
--fs_license /fs_license/license.txt \
--t1 /data/subjectX/orig.mgz \
--sid subjectX --sd /output
Note the system requirements of at least 8 GB system memory and 2 GB graphics memory for the GPU version. If the process fails, check if your WSL2 distribution has enough memory reserved.