voxelmorph icon indicating copy to clipboard operation
voxelmorph copied to clipboard

Questions about installation and versions

Open GerardoPerezRojas01 opened this issue 11 months ago • 3 comments

Good morning, my name is Gerardo Perez, I am a PhD student in Physics and I would like to use the "SynthMorph" module for image registration and neural network training.I have some questions related to this topic since when I want to use it in Google Colab it appears that the TensorFlow version is not correct,What versions of TensorFlow is the "voxelmorp" library compatible with? If I want to install on my computer, where can I download these libraries since I use Windows? Do you have any quick start tutorial for installation? Thank you very much in advance and have a nice day

GerardoPerezRojas01 avatar Jan 14 '25 15:01 GerardoPerezRojas01

I can't help you with all your questions but I can try to help for some. The deformable SynthMorph demo is a working SynthMorph tutorial with no tensorflow version problem. If you are using the main VoxelMorph tutorial then it is normal as it is out of date. To solve the import issue, you can use:

!pip -q install git+https://github.com/adalca/neurite.git@0776a575eadc3d10d6851a4679b7a305f3a31c65  
!pip -q install git+https://github.com/voxelmorph/voxelmorph.git@375a1492bb8781cbbaf22f0ca2973e5121484f99

Instead of:

!pip install voxelmorph

As I didn't spot any incompatibility, tensorflow verison 2.18 should be compatible (probably 2.17 as well). In short, if you have the latest version, it should be good to go. But here comes the problem, tensorflow dropped gpu support on windows as of version 2.10. As such, I cannot guarantee you'll be able to install a compatible version on windows. It might be different on WSL but I can't confirm.

20millot avatar Mar 01 '25 05:03 20millot

I'm adding to this comment as it's related to versions & installation (for now) - will split into a new issue as appropriate w/r/t answers....

I've been working to get Synthmorph running on Win11 as I have a computer with a 3090 24GB and I wanted to see how it performed.

The approach I took was to use WSL (v2) with Ubuntu 22.04 and install the Freesurfer version. Sadly, this version segfaults when performing registration. I couldn't even get it to run long enough to get to even eval CPU vs GPU.

So, I moved on to the Dockerized synthmorph, running inside the same WSL Ubuntu 22.04. After a lot of fiddling, I was able to successfully get the GPU to be used! This required a few changes in the Docker setup (mostly the synthmoprh wrapper script that calls Docker). I was surprised to learn that even my 24GB card was insufficient to run the 256 extent deformable model. And, probably due to GPU memory pressure, while the 192 extent ran, it was actually slower than the same binary with GPU disabled (I have a 20-core machine w 24GB RAM).

So, in any case..

  1. Would you like me to submit the changes to the Docker so that if people want it can be used for GPU-accelerated work? I couldn't find that codebase....

  2. It is known that the FresSurfer 8 Ubuntu 22.04 doesn't work (maybe just on WSL?) If not, I could potentially log some debug info if helpful.

  3. From a requirements perspective, how much GPU RAM is needed to run the joint deformable model on GPU, and is it a good speedup relative to CPU?

apinstein avatar Jun 24 '25 01:06 apinstein

  • Would you like me to submit the changes to the Docker so that if people want it can be used for GPU-accelerated work? I couldn't find that codebase....

FYI here is the Dockerfile I made to modify the synthmorph Dockerfile to help debug GPU - it logs the tensorflow ops along with which device was used...

FROM freesurfer/synthmorph:4

# Apply your debug line to registration.py
RUN sed -i "/import tensorflow as tf/a tf.debugging.set_log_device_placement(True)" /freesurfer/synthmorph/registration.py && grep -A 2 import.tensorflow /freesurfer/synthmorph/registration.py
#RUN sed -i '/tf.debugging.set_log_device_placement(True)/a for gpu in tf.config.list_physical_devices("GPU"):\n    tf.config.experimental.set_memory_growth(gpu, True)' /freesurfer/synthmorph/registration.py
#RUN sed -i '/tf.debugging.set_log_device_placement(True)/a from tensorflow.keras import mixed_precision\nmixed_precision.set_global_policy("mixed_float16")' /freesurfer/synthmorph/registration.py


RUN sed -i "/from synthmorph import registration/a \    print(f'FINAL CUDA_VISIBLE_DEVICES: {os.environ[\"CUDA_VISIBLE_DEVICES\"]}')\n    print(f'TF_CPP_MIN_LOG_LEVEL: {os.environ[\"TF_CPP_MIN_LOG_LEVEL\"]}')" /freesurfer/mri_synthmorph && grep -B 10 "from synthmorph import registration" /freesurfer/mri_synthmorph

RUN sed -i "/fw, bw = map(tf.squeeze, model(inputs))/i \    import time\n    print(tf.config.list_physical_devices('GPU'))\n    print(\"===== Running model inference =====\")\n    tf.debugging.set_log_device_placement(True)\n    start = time.time()" /freesurfer/synthmorph/registration.py && \
    sed -i "/fw, bw = map(tf.squeeze, model(inputs))/a \    end = time.time()\n    print(f\"===== Model inference took {end - start:.2f} seconds =====\")" /freesurfer/synthmorph/registration.py

And in the wrapper synthmorph command that's created to run synthmoprh in docker, this was needed to be added:

--gpus all -e CUDA_VISIBLE_DEVICES=0

Just documenting here since I'm not sure where to do a PR on it (and ofc this isn't the appropriate long-term solution)

apinstein avatar Jun 24 '25 18:06 apinstein