Hi, I'm trying to get this to run with the docker version on a Macbook Pro M2 using some data from TCIA but am getting the errors shown in the attached document after trying with 2 different DICOM series. Any idea what's wrong?
Justin,
I don't have any experience with your error, but from Googling it,
it seems to be a Mac specific issue. Several suggestions are
offered here: https://stackoverflow.com/questions/6666... That
addresses this warning "WARNING: The requested image's platform
(linux/amd64) does not match the detected host platform
(linux/arm64/v8) and no specific platform was requested", and I
hope that would fix the subsequent errors of "chmod: Invalid file
mode: =777" and "Error: mclmcr initialization failed" issue with
the Matlab runtime.
Hopefully this will correct your first example, but I think your second example wouldn't work either way, based on "Warning: Interslice distance varies in this volume (incompatible with NIfTI format).". If your DICOM can't be converted into a .nii file with dcm2niix, then it won't be compatible. If you have some other converter that successfully makes a .nii out of it, you could run that externally and create a new de-faced nifti with mri_reface, then convert that back with ADIR_nii2dicom (but using it with the old DICOM may not work, since it still has the original issues that caused it to fail with dcm2niix).
Hope that helps!
Chris
Thanks Chris. I tried editing the run_mri_reface_docker.sh to add "--platform linux/amd64" to the docker run command. This eliminates the warning since I'm specifying a platform, but that didn't resolve the error about mclmcr initialization, which I assume is because that isn't the actual hardware I'm using.
If I update the script to specify "--platform linux/arm64/v8" I get an error that's essentially indicating an image for mri_reface with that platform doesn't exist on dockerhub.
After digging into this a little, I read that you should be able to specify that you want to provide a Mac release tailored for Apple silicon using BuildX when you create your Docker image. E.g. "docker buildx build --platform linux/arm64 -t my-image:latest". I'd be happy to test this out for you if that's something you can try.
Also, I was able to fix the "chmod: Invalid file mode: =777" error I was getting by editing your .sh file to remove the space before the = in that line. I.e. "chmod =777 -R $tmpdir" --> "chmod=777 -R $tmpdir". I guess Macs are fussier about this syntax than PCs.
Justin,
We're going to have to take some time to look into this and get
back to you. Your post was news to me that Docker images are not
cross-architecture, but producing the mri_reface Docker was really
the first forray into containers for me and my team. Our docker
build is a little unusual because of the Matlab runtime. We have to
use Matlab's own Docker-building functionality to build a working
image containing the Matlab runtime, and then use that output as
the base for us to add additional layers with our program and
the rest of its dependencies. Installing the off-the-shelf Matlab
runtime in our Docker environments produces OpenGL errors in some
of the function calls we use, and this only seems to happen inside
Docker images (you can find old messages about that on this board).
The one installed by Matlab's own docker-builder avoids this; it
seems to be a special version somehow. I suspect that these issues
will make it a lot tougher to build an image for arm64 that also
contains the Matlab runtimes for arm64. One of my colleagues has an
M2 laptop and has offered to help test. In short, I want to help
you and other arm64/Apple users, but I think it will be a bigger
undertaking than the average Docker image. Please be patient, and I
will get back to you. In the meantime, my best suggestion is to use
our corresponding not-Docker release. You can install the
appropriate Matlab runtime, compile niftyreg and ANTs, and
hopefully that would work around your issue. For your hardware, the
Docker solution may be creating more issues than it is solving.
Best,
Chris
Hi Chris,
I am also struggling to run mri_reface on my m1 mac. I have tried running both the docker and non-docker versions with no success. When testing the docker version, I similarly get an error about mclmcr. I have tried the MATLAB runtimes for 2022a, 2023a, and 2024b (arm64). When using the non-docker version, I get the error, 'cannot execute binary file.' I have already checked that the executable is allowed by my mac permissions. My guess is that the exe distributed in the non-docker version is not compiled for arm64 architecture, but I am admittedly a novice in these things.
Do you have any updates on testing mri_reface with m-type architectures?
Thanks,
James
James,
Thank you for letting me know that the not-Docker version isn't
compatible with arm64 either. We are gearing up to release a new
version in the coming weeks. At that time, I will try to run the
compile script on my wife's Macbook, and hopefully it will work to
let me provide a mac release.
Best,
Chris
Hi Mac folks,
I have been able to make a non-Docker build of (upcoming version)
0.3.5 that runs successfully on Apple Silicon. mri_reface is
currently built on matlab2022a, which does not have native support
for ARM, but they support it via Rosetta. Matlab added native
support in a later version, but for now, the mri_reface Mac build
will run on Rosetta (which I believe is a common default install).
The bad news is Matlab's Docker building functions only support
Linux, so it's going to be more difficult (or maybe impossible) to
make a good Apple Docker build. For the Linux Docker builds we
found that packaging the standard matlab Linux runtime into Docker
had bugs, and it only really worked using Matlab's special Docker
images, which are apparently for Linux only. So, the good news is
we will soon release a 0.3.5 with a new Mac build, but the bad news
is it won't have a Docker version, at least for now. Mac users will
need to compile the two dependencies (niftyreg aka reg_aladin, and
ANTS) on their own, but I was able to compile these with minimal
difficulty (disable SSE for Niftyreg; otherwise standard defaults
were fine). So, you can expect a (non-Docker) Mac build with 0.3.5
release in the coming weeks. I am doing final testing for this now,
and the Mac build was part of that.
Chris
Hi James and Justin, the 0.3.5 Mac version is now released. This has the same requirements as current Linux builds: Matlab2022a runtime (free), reg_aladin (niftyreg), ANTS. Tested on MacOS Sequoia 15.1.1 with an M2 "Silicon" chip. DICOM support was tested with dcm2niix (20241208 from Macports) and Python (3.10.16 from Macports) with modules pydicom 3.0.1 and nibabel 5.3.2. Please let me know if this works for you, and thank you for your patience as I worked on this.
Thank you for putting together the ARM Mac release! I tried to run it on my m1 macbook (running macOS Ventura 13.6.7) and I am no longer blocked by the mclmcr error, but it is still failing to run. I compiled ANTs and niftyreg from the source code on Github, and I am using the Matlab 2022a runtime. Note that I was able to generate the refaced MRI using the same input file on my PC using the docker version and an Ubuntu shell. You can see the output message below:
jamesswift@Jamess-MacBook-Pro-2 ~ % export MCRROOT=/Applications/MATLAB/MATLAB_Runtime/v912
export PATH=$PATH:/Users/jamesswift/Documents/git/ANTs:/Users/jamesswift/Documents/git/ANTs/install/bin:/Users/jamesswift/Documents/git/ANTs/install/lib:/Users/jamesswift/Documents/git/niftyreg:/Users/jamesswift/Documents/git/niftyreg/niftyreg_install/bin:/Users/jamesswift/Documents/git/niftyreg/niftyreg_install/include:/Users/jamesswift/Documents/git/niftyreg/niftyreg_install/lib:/Users/jamesswift/Documents/git/dcm2niix/build/bin
/Users/jamesswift/Documents/VERA_dependencies/mri_reface/run_mri_reface.sh /Users/jamesswift/Documents/mri_reface_test/MRI_T1.nii /Users/jamesswift/Documents/mri_reface_test/output -imType T1
-------------------------------------------------------
Running mri_reface, version 0.3.5
By: Christopher G. Schwarz schwarz.christopher@mayo.edu
Temp directory: /private/var/folders/g8/x6kv8v7x1gn4n1t041zj1xcm0000gn/T/tp250ef495_d073_433a_ba50_9eb875100d51
Target file: /Users/jamesswift/Documents/mri_reface_test/MRI_T1.nii
Output directory: /Users/jamesswift/Documents/mri_reface_test/output
Target image type: T1
Template: /Users/jamesswift/Documents/VERA_dependencies/mri_reface/mri_reface.app/Contents/Resources/mri_reface_mcr/mri_reface/images/MCALT_FaceTemplate_T1.nii
Face atlas: /Users/jamesswift/Documents/VERA_dependencies/mri_reface/mri_reface.app/Contents/Resources/mri_reface_mcr/mri_reface/images/MCALT_FaceMask.nii
Calculating affine parameters to template. This will take some time.
Using face-optimized affine.
Estimating warp to template using ANTS. This will take a while.
Error using ADIR_ReFace
ANTS 3 -m CC[
/Users/jamesswift/Documents/VERA_dependencies/mri_reface/mri_reface.app/Contents/Resources/mri_reface_mcr/mri_reface/images/MCALT_FaceTemplate_T1.nii
, MRI_T1_forCoreg.nii, 1, 5 ] -o MRI_T1_to_MCALT_FaceTemplate_ -x
/Users/jamesswift/Documents/VERA_dependencies/mri_reface/mri_reface.app/Contents/Resources/mri_reface_mcr/mri_reface/images/MCALT_FaceTemplate_FaceWarpMask.nii
-a MRI_T1_to_MCALT_FaceTemplate_InitAffine.txt --continue-affine 0
-number-of-affine-iterations 0 -i 30x90x20 -r Gauss[3,0] -t SyN[.25]failed with
output: zsh:1: bad pattern: CC[
Do you have any suggestions for this "bad pattern" error? I haven't been able to find the file MRI_T1_to_MCALT_FaceTemplate_InitAffine.txt. I also was able to use ANTs to coregister two images with no issues outside of your project.
Thank you again for all of the support!
Hi, can you try setting the default shell on your Mac to bash instead of zs=
h? I had changed that setting when I tested, and from what you pasted, the =
error seems to be coming from zsh. Please let me know if that works.
Thanks,
Chris
Yes, this fixed the problem right away! I added 'chsh -s /bin/bash' to line 132 of run_mri_reface.sh and it worked.
Thank you!
Excellent! We can make this change in the next release. Thanks for your fast confirmation!