Deep-MI / FastSurfer
- воскресенье, 28 июня 2020 г. в 00:22:58
Python
PyTorch implementation of FastSurferCNN
This directory contains all information needed to run FastSurfer - a fast and accurate deep-learning based neuroimaging pipeline. This approach provides a full FreeSurfer alternative for volumetric analysis (within 1 minute) and surface-based thickness analysis (within only around 1h run time). It consists of two main parts:
(i) FastSurferCNN - an advanced deep learning architecture capable of whole brain segmentation into 95 classes in under 1 minute, mimicking FreeSurfer’s anatomical segmentation and cortical parcellation (DKTatlas)
(ii) recon-surf - full FreeSurfer alternative for cortical surface reconstruction, mapping of cortical labels and traditional point-wise and ROI thickness analysis in approximately 60 minutes.
Within this repository, we provide the code and Docker files for running FastSurferCNN (segmentation only) and recon-surf (surface pipeline only) independently from each other or as a whole pipeline (run_fastsurfer.sh, segmentation + surface pipeline). For each of these purposes, see the README.md's in the corresponding folders.
The FastSurferCNN and recon_surf directories contain all the source code and modules needed to run the scripts. A list of python libraries used within the code can be found in requirements.txt.
There are two ways to run FastSurfer - (a) locally or (b) using Docker.
(a) For a local version, download this github repository (use git clone or download as zip and unpack) for the necessary source code and python scripts. If you also have the necessary python libraries installed (see above), this is already enough to generate the whole-brain segmentation using FastSurferCNN (see the README.md in the FastSurferCNN directory for the exact commands). In order to run the whole FastSurfer pipeline locally on your machine, a working version of FreeSurfer (v6.0, https://surfer.nmr.mgh.harvard.edu/fswiki/rel6downloads) is needed (specifically to run recon-surf), as well as some python packages (nibabel, torch, torchvision, scipy, scikit-image, h5py). See Example 1 and Example 2 for an illustration of the commands to run the entire FastSurfer pipeline (FastSurferCNN + recon-surf) locally.
(b) For a dockerized version, simply use the provided Dockerfiles in our Docker directory to build your image (see the README.md in the Docker directory). No other local installations are needed (FreeSurfer and everything else is already included). See Example 3 for a working example.
The main script called run_fastsurfer.sh can be used to run both FastSurferCNN and recon-surf sequentially on a given subject. There are a number of options which can be selected and set via the command line. List them by running the following command:
./run_fastsurfer.sh --help
Given you want to analyze data for subject1 which is stored on your computer under /home/user/my_mri_data/subject1/orig.mgz, run the following command from the console (do not forget to source FreeSurfer!):
# Source FreeSurfer
export FREESURFER_HOME=/path/to/freesurfer/fs60
source $FREESURFER_HOME/SetUpFreeSurfer.sh
# Define data directory
datadir=/home/user/my_mri_data
fastsurferdir=/home/user/my_fastsurfer_analysis
# Run FastSurfer
./run_fastsurfer.sh --fs_license /path/to/freesurfer/fs60/.license \
--t1 $datadir/subject1/orig.mgz \
--seg $fastsurferdir/subject1/aparc.DKTatlas+aseg.deep.mgz \
--sid subject1 --sd $fastsurferdir \
--mc --qspec --nofsaparc --parallel --threads 4
The output will be stored in the $fastsurferdir (including the aparc.DKTatlas+aseg.deep.mgz segmentation).
In order to run FastSurfer on a number of cases which are stored in the same directory, prepare a subjects_list.txt file listing the names line per line: subject1\n subject2\n subject3\n ... subject10\n
And invoke the following command (make sure you have enough ressources to run the given number of subjects in parallel!):
export FREESURFER_HOME=/path/to/freesurfer/fs60
source $FREESURFER_HOME/SetUpFreeSurfer.sh
cd /home/user/FastSurfer
datadir=/home/user/my_mri_data
fastsurferdir=/home/user/my_fastsurfer_analysis
mkdir $fastsurferdir/logs # create log dir for storing nohup output log (optional)
while read p ; do
echo $p
nohup ./run_fastsurfer.sh --fs_license /path/to/freesurfer/fs60/.license \
--t1 $datadir/$p/orig.mgz \
--seg $fastsurferdir/$p/aparc.DKTatlas+aseg.deep.mgz \
--sid $p --sd $fastsurferdir \
--mc --qspec --nofsaparc > $fastsurferdir/logs/out-${p}.log &
sleep 90s
done < ./data/subjects_list.txt
After building the Docker (see instructions in ./Docker/README.md), you do not need to have a separate installation of FreeSurfer on your computer (included in the Docker). However, you need to register at the FreeSurfer website (https://surfer.nmr.mgh.harvard.edu/registration.html) to acquire a valid license (for free).
To run FastSurfer on a given subject using the provided Docker, execute the following command:
docker run --gpus all -v /home/user/my_mri_data:/data \
-v /home/user/my_fastsurfer_analysis:/output \
-v /home/user/my_fs_license_dir:/fs60 \
--rm --user XXXX fastsurfer:gpu \
--fs_license /fs60/.license \
--t1 /data/subject2/orig.mgz \
--seg /output/subject2/aparc.DKTatlas+aseg.deep.mgz \
--sid subject2 --sd /output \
--mc --qspec --nofsaparc --parallel
If you use this for research publications, please cite:
Henschel L, Conjeti S, Estrada S, Diers K, Fischl B, Reuter M, FastSurfer - A fast and accurate deep learning based neuroimaging pipeline, NeuroImage 219 (2020), 117012. https://doi.org/10.1016/j.neuroimage.2020.117012
The recon-surf pipeline is largely based on FreeSurfer including the use of one binary (mris_make_surfaces) from the dev version. https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferMethodsCitation