Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Mac support and clean up dependencies #530

Merged
merged 12 commits into from
Jun 19, 2024
2 changes: 1 addition & 1 deletion FastSurferCNN/segstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def read_classes_from_lut(lut_file: str | Path):
}
return pd.read_csv(
lut_file,
delim_whitespace=True,
sep='\s+',
index_col=False,
skip_blank_lines=True,
comment="#",
Expand Down
2 changes: 1 addition & 1 deletion FastSurferCNN/utils/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def __init__(

self._data = pandas.read_csv(
file_or_buffer,
delim_whitespace=True,
sep='\s+',
index_col=0,
skip_blank_lines=True,
comment="#",
Expand Down
17 changes: 6 additions & 11 deletions doc/overview/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,17 @@ Continue with the example in [Example 1](EXAMPLES.md#example-1-fastsurfer-docker

### Native

On modern Macs with the Apple Silicon M1 or M2 ARM-based chips, we recommend a native installation as it runs much faster than Docker in our tests. The experimental support for the built-in AI Accelerator is also only available on native installations. Native installation also supports older Intel chips.
On modern Macs with the Apple Silicon M1 or M2 ARM-based chips, we recommend a native installation as it runs much faster than Docker in our tests. The experimental support for the built-in AI accelerator (MPS) is also only available on native installations. Native installation also supports older Intel chips.

#### 1. Git and Bash
If you do not have git and a recent bash (version > 4.0 required!) installed, install them via the packet manager, e.g. brew.
If you do not have git you can install it via the packet manager, e.g. brew.
This installs brew and then bash:

```sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install bash
brew install git
```

Make sure you use this bash and not the older one provided with MacOS!

#### 2. Python
Create a python environment, activate it, and upgrade pip. Here we use pip, but you should also be able to use conda for python:

Expand All @@ -195,7 +193,6 @@ cd FastSurfer
export PYTHONPATH="${PYTHONPATH}:$PWD"
```


Install the FastSurfer requirements
```sh
python3 -m pip install -r requirements.mac.txt
Expand All @@ -215,14 +212,12 @@ You can also download all network checkpoint files (this should be done if you a
python3 FastSurferCNN/download_checkpoints.py --all
```

Once all dependencies are installed, run the FastSurfer segmentation only (!!) by calling ```bash ./run_fastsurfer.sh --seg_only ....``` with the appropriate command line flags, see the [commandline documentation](../../README.md#usage).

Note: You may always need to prepend the command with `bash` (i.e. `bash run_fastsurfer.sh <...>`) to ensure that bash 4.0 is used instead of the system default.
Once all dependencies are installed, you can run the FastSurfer segmentation only by calling ```./run_fastsurfer.sh --seg_only ....``` with the appropriate command line flags, see the [commandline documentation](../../README.md#usage).

To run the full pipeline, install and source also the supported FreeSurfer version according to their [Instructions](https://surfer.nmr.mgh.harvard.edu/fswiki/rel7downloads). There is a freesurfer email list, if you run into problems during this step.
To run the full pipeline, install and source also the supported FreeSurfer version according to their [Instructions](https://surfer.nmr.mgh.harvard.edu/fswiki/rel7downloads). There is a freesurfer email list, if you run into problems during this step. Note, that currently FreeSurfer for MacOS supports no ARM, but only Intel, so on modern M-chips it might be slow due to the emulation.

#### 4. Apple AI Accelerator support
You can also try the experimental support for the Apple Silicon AI Accelerator by setting `PYTORCH_ENABLE_MPS_FALLBACK` and passing `--device mps`:
You can also try the experimental support for 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:

```sh
export PYTORCH_ENABLE_MPS_FALLBACK=1
Expand Down
26 changes: 14 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ classifiers = [
]
dependencies = [
'h5py>=3.7',
'lapy>=0.4.1',
'matplotlib>=3.5.1',
'nibabel>=3.2.2',
'numpy>=1.21',
'pandas>=1.4.3',
'torch>=1.12.0',
'lapy>=1.0.1',
'matplotlib>=3.7.1',
'nibabel>=5.1.0',
'numpy>=1.25,<2',
'pandas>=1.5.3',
'pyyaml>=6.0',
'scipy>=1.8.0',
'yacs>=0.1.8',
'simpleitk>=2.1.1',
'scipy>=1.8.0',
'tensorboard>=2.9.1',
'scikit-image>=0.19.3',
'scikit-learn>=1.2.2',
'scipy>=1.10.1,!=1.13.0',
'simpleitk>=2.2.1',
'tensorboard>=2.12.1',
'torch>=2.0.1',
'torchio>=0.18.83',
'tqdm>=4.64',
'torchvision>=0.15.2',
'tqdm>=4.65',
'yacs>=0.1.8',
]

[project.optional-dependencies]
Expand Down
31 changes: 16 additions & 15 deletions recon_surf/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ function RunIt()
if [[ $# -eq 3 ]]
then
local CMDF=$3
echo "echo ${cmd@Q}" |& tee -a $CMDF
echo "$timecmd $cmd" |& tee -a $CMDF
printf -v tmp %q "$cmd"
echo "echo $tmp" 2>&1 | tee -a $CMDF
echo "$timecmd $cmd" 2>&1 | tee -a $CMDF
echo "if [ \${PIPESTATUS[0]} -ne 0 ] ; then exit 1 ; fi" >> $CMDF
else
echo $cmd |& tee -a $LF
$timecmd $cmd |& tee -a $LF
echo $cmd 2>&1 | tee -a $LF
$timecmd $cmd 2>&1 | tee -a $LF
if [ ${PIPESTATUS[0]} -ne 0 ] ; then exit 1 ; fi
fi
}
Expand Down Expand Up @@ -107,21 +108,21 @@ function softlink_or_copy()
if [[ $# -eq 4 ]]
then
local CMDF=$4
echo "echo \"$ln_cmd\" " |& tee -a $CMDF
echo "$timecmd $ln_cmd " |& tee -a $CMDF
echo "if [ \${PIPESTATUS[0]} -ne 0 ]" |& tee -a $CMDF
echo "then " |& tee -a $CMDF
echo " echo \"$cp_cmd\" " |& tee -a $CMDF
echo " $timecmd $cp_cmd " |& tee -a $CMDF
echo "echo \"$ln_cmd\" " 2>&1 | tee -a $CMDF
echo "$timecmd $ln_cmd " 2>&1 | tee -a $CMDF
echo "if [ \${PIPESTATUS[0]} -ne 0 ]" 2>&1 | tee -a $CMDF
echo "then " 2>&1 | tee -a $CMDF
echo " echo \"$cp_cmd\" " 2>&1 | tee -a $CMDF
echo " $timecmd $cp_cmd " 2>&1 | tee -a $CMDF
echo " if [ \${PIPESTATUS[0]} -ne 0 ] ; then exit 1 ; fi" >> $CMDF
echo "fi" |& tee -a $CMDF
echo "fi" 2>&1 | tee -a $CMDF
else
echo $ln_cmd |& tee -a $LF
$timecmd $ln_cmd |& tee -a $LF
echo $ln_cmd 2>&1 | tee -a $LF
$timecmd $ln_cmd 2>&1 | tee -a $LF
if [ ${PIPESTATUS[0]} -ne 0 ]
then
echo $cp_cmd |& tee -a $LF
$timecmd $cp_cmd |& tee -a $LF
echo $cp_cmd 2>&1 | tee -a $LF
$timecmd $cp_cmd 2>&1 | tee -a $LF
if [ ${PIPESTATUS[0]} -ne 0 ] ; then exit 1 ; fi
fi
fi
Expand Down
Loading