Deep-MI / FastSurfer

PyTorch implementation of FastSurferCNN
Apache License 2.0
460 stars 120 forks source link

Unable to run FreeSurfer thalamic nuclei segmentation after FastSurfer without recon-all #607

Closed aritban1github closed 5 days ago

aritban1github commented 2 weeks ago

Hello Fastsurfer community,

I am encountering persistent issues while trying to run thalamic nuclei segmentation using FreeSurfer 7.4.1 in a Singularity container after running FastSurfer. Here’s a detailed summary of my situation:

FreeSurfer version: 7.4.1 (freesurfer-linux-centos8_x86_64-7.4.1-20230613-7eb8460)

I have successfully run FastSurfer, which completed the segmentation. Here’s the output structure:

subject1/ ├── mri/ │ ├── aparc.DKTatlas+aseg.deep.mgz │ ├── aseg.auto_noCCseg.mgz │ ├── atlas_registered.nii.gz │ ├── cerebellum.CerebNet.nii.gz │ ├── mask.mgz │ ├── orig/ │ ├── orig.mgz │ ├── orig_converted.nii.gz │ ├── orig_nu.mgz │ └── transform.mat ├── scripts/ │ └── deep-seg.log └── stats/ ├── aseg+DKT.stats └── cerebellum.CerebNet.stats

I am now trying to run the FreeSurfer thalamic nuclei segmentation without running recon-all, as I understand this should be possible directly on the FastSurfer output.

The command I am attempting to use for thalamic nuclei segmentation is:

singularity exec -B /path/to/fastsurfer/output:/data -e /path/to/freesurfer.sif bash -c ‘export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freesurfer/MCRv97/runtime/glnxa64:/usr/local/freesurfer/MCRv97/bin/glnxa64:/usr/local/freesurfer/MCRv97/sys/os/glnxa64:/usr/local/freesurfer/MCRv97/extern/bin/glnxa64 && export MCR_CACHE_ROOT=/path/to/mcr_cache && segmentThalamicNuclei.sh subject1 /data/fastsurfer_output’

When trying to run this command, I get an error indicating that the MATLAB Runtime (MCR) 2019b is not found.

I have attempted to install MCR using fs_install_mcr R2019b, but the installation fails with the following error:

mv: inter-device move failed: ‘/tmp/tmp.XXXXXXXX/install-target/v97’ to ‘/usr/local/freesurfer/MCRv97’; unable to remove target: Read-only file system

I have tried various approaches to resolve this issue, including: Binding different directories Setting LD_LIBRARY_PATH Creating symbolic linksNone of these attempts have been successful.

My questions are:

  1. Is there a known issue with running thalamic nuclei segmentation on FastSurfer output without recon-all?
  2. Are there any specific steps or workarounds for installing MCR in a read-only Singularity container when working with FastSurfer output?
  3. Is there an alternative method to run thalamic nuclei segmentation on FastSurfer output without relying on MCR?
  4. Are there any additional files or preprocessing steps needed for thalamic nuclei segmentation that might be missing from the FastSurfer output?
  5. Given that I have tried binding directories, setting LD_LIBRARY_PATH, and creating symbolic links without success, are there any other troubleshooting steps you’d recommend?

Any guidance or suggestions would be greatly appreciated. Please let me know if you have any questions. Thank you in advance for your help and thanks to the Fastsurfer community!

m-reuter commented 2 weeks ago

Hi, there are a few things.

First, I would recommend to ask the FreeSurfer mailing list on how to run their tools which we cannot support here. For that I would recommend you run FreeSurfer recon-all on your data and then on top of that the Thalamic sub-segmentation. They should be able to help you get that working. Once it does you can replace the slow recon-all step with FastSurfer.

Second, probably the Thalamic sub-segmentation in FreeSurfer needs results from the surfaces. Please post your command that you use to run FastSurfer, it looks like you only run the segmentation module (--seg_only). This will probably not be sufficient (but I don't know for sure). In that case you should try to run the full FastSurfer pipeline, which will also create surfaces.

So about your questions:

  1. We don't know about any issue. In fact we successfully tested it a while ago.
  2. You can build a new image with the right MCR in it, but we are not able to help much, as this is a FreeSurfer container and has nothing to do with FastSurfer, also the Matlab error is a problem with their Singularity Image.
  3. No, probably it is needed by their thalamic nuclei tool.
  4. What files their method needs should be documented with their method, we don't know for sure.
  5. Again, we cannot help you here to get FreeSurfer tools running. Try a full FreeSurfer approach first, then replace recon-all with FastSurfer and try again.
m-reuter commented 2 weeks ago

Actually it could be that only the segmentation and the norm.mgz are needed (which are basically available). Let us know once you know what the exact input files are. Instead of the norm.mgz you could try the orig_nu.mgz (or a masked version of that, the mask is also there) and for the aseg, you can take the aseg.auto_noCCseg.mgz . If they also need the Corpus Callosum labels, then you would need to run until that is available but can skip the time consuming surfaces. If that turns out to be sufficient, we could create a special flag for stopping there in a future release. We are planing to move the CC seg into the segmentation block anyway (currently it is in the surface block) with a new deep learning tool in one of the future releases.

m-reuter commented 5 days ago

Closing this due to inactivity for now. We had tested this before and it worked, so it is most likely a problem with the specific setup that you have.

aritban1github commented 5 days ago

Hello Dr. Reuter,

Apologies for the delayed reply. I was able to resolve the issue. The entire problem stemmed from running the shorter FastSurfer pipeline initially instead of the longer FastSurfer pipeline, followed by the FreeSurfer thalamic nuclei segmentation.

This is how the code should look like, I ran it using singularity -

Run FastSurfer processing using Singularity with GPU

singularity exec --nv \ --no-home \ -B /data:/data \ -B /output:/output \ -B /fs_license:/fs_license \ ~/bin/fastsurfer-gpu.sif \ /bin/bash -c "/bin/bash /fastsurfer/run_fastsurfer.sh \ --t1 /data/T1.nii.gz \ --sd /output \ --sid subjectX \ --fs_license /fs_license/license.txt \ --parallel"

Start Singularity shell with Freesurfer image for thalamic nuclei

segmentation singularity shell -B /data:/data \ -B /output:/output \ -B /fs_license:/fs_license \ --env FS_LICENSE=/fs_license/license.txt \ ~/bin/freesurfer_7.4.1_20231214.simg <<EOF

(you need to download curl -X GET https://neurocontainers.neurodesk.org/freesurfer_7.4.1_20231214.simg -O before)

Set SUBJECTS_DIR environment variable

export SUBJECTS_DIR=/output

Navigate to subject directory

cd /output/subjectX/mri

Run thalamic nuclei segmentation

segmentThalamicNuclei.sh subjectX

Exit the singularity shell

exit EOF

Thank you so much for your help! FastSurfer is of great help to me.

On Wed, Nov 20, 2024 at 9:01 AM Martin Reuter @.***> wrote:

Closing this due to inactivity for now. We had tested this before and it worked, so it is most likely a problem with the specific setup that you have.

— Reply to this email directly, view it on GitHub https://github.com/Deep-MI/FastSurfer/issues/607#issuecomment-2488663882, or unsubscribe https://github.com/notifications/unsubscribe-auth/A24B665OB5IT74BD2QCKIPT2BSI4ZAVCNFSM6AAAAABRQVKC4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBYGY3DGOBYGI . You are receiving this because you authored the thread.Message ID: @.***>