Deep-MI / FastSurfer

PyTorch implementation of FastSurferCNN
Apache License 2.0
459 stars 119 forks source link

wmparc file? #30

Closed vinkirk closed 3 years ago

vinkirk commented 4 years ago

Hi,

Is FastSurfer able to generate a wmparc.mgz that is found in FreeSurfer? If so, can you please advise on how to do this.

Thanks for your help,

Vinny

m-reuter commented 4 years ago

Hi Vinny,

in the surface stream we are also mapping the cortical labels into the WM just like FreeSurfer does. This means you need to run FastSurfer all the way to the end to get these files. There you will get wmparc.mapped.mgz (which is the FastSurferCNN cortical labels mapped into the WM) and depending on the flags you use, you can also get wmparc.mgz which is a FreeSurfer based surface segmentation mapped into WM (requires atlas registration and will take longer though). I recommend to start with the *mapped.mgz version. Note that FastSurfer uses the DKT atlas so our labels will be slightly different from the Freesurfer ones (some cortical regions are merged, as described in the DKT paper).

We also experimented with predicting WMparc directly and had some success to get those Segmentations , so maybe eventually it will be possible to get those within 1 minute from a T1 or even from Diffusion data directly.

vinkirk commented 4 years ago

Thanks for your reply. I am not clear on when you mentioned about running FastSurfer all the way to the end to get the wmparc.mapped.mgz file. What command would need to be executed? I had used the run_fastsurfer.sh command as per the tutorials and assumed this ran the complete FastSurfer volumetric- and surface-based registration. Please note that I am running FastSurfer as a native install.

m-reuter commented 4 years ago

It is one of the last steps in the recon-surf subscripts (surface pipeline). It is run by default when using run_fastsurfer.sh. Are you sure there is no wmparc.mapped.mgz in the subject/mri directory? If it is missing, probably your run terminated early (check the recon-surf.log file).

vinkirk commented 4 years ago

Ok I see what you're saying.... these are the last few lines from the recon-surf.log file. I am using Ubuntu 20.04 and had edited the bashrc profile to include FastSurfer.

@#@FSTIME 2020:08:20:22:35:25 mris_sample_parc N 14 e 34.99 S 9.52 U 14.69 P 69% M 15257588 F 18493 R 8926417 W 0 c 940 w 19055 I 279712 O 2064 L 1.00 1.00 1.01 @#@FSLOADPOST 2020:08:20:22:36:00 mris_sample_parc N 14 1.24 1.06 1.03 python3.6 smooth_aparc.py --insurf /home/vinny/Tools/fastsurfer/subj1/surf/lh.white.preaparc --inaparc /home/vinny/Tools/fastsurfer/subj1/label/lh.aparc.mapped.prefix.annot --incort /home/vinny/Tools/fastsurfer/subj1/label/lh.cortex.label --outaparc /home/vinny/Tools/fastsurfer/subj1/label/lh.aparc.mapped.annot Reading in surface: /home/vinny/Tools/fastsurfer/subj1/surf/lh.white.preaparc ... Reading in annotation: /home/vinny/Tools/fastsurfer/subj1/label/lh.aparc.mapped.prefix.annot ... Reading in cortex label: /home/vinny/Tools/fastsurfer/subj1/label/lh.cortex.label ... Non-cortex vertices with labels: 43 Command terminated by signal 11 @#@FSTIME 2020:08:20:22:36:01 python3.6 N 9 e 1.45 S 0.12 U 0.79 P 62% M 91204 F 266 R 22544 W 0 c 3 w 1035 I 135704 O 0 L 1.24 1.06 1.03 @#@FSLOADPOST 2020:08:20:22:36:02 python3.6 N 9 1.22 1.06 1.03 Command exited with non-zero status 1 @#@FSTIME 2020:08:20:21:43:11 /home/vinny/Tools/fastsurfer/subj1/scripts/lh.processing.cmdf N 0 e 3171.12 S 12.67 U 3147.02 P 99% M 15257588 F 19100 R 11532725 W 0 c 15061 w 23647 I 484552 O 155296 L 1.03 1.27 1.54 @#@FSLOADPOST 2020:08:20:22:36:02 /home/vinny/Tools/fastsurfer/subj1/scripts/lh.processing.cmdf N 0 1.22 1.06 1.03

m-reuter commented 4 years ago

yes, there is an error: non-zero status 1. You know FastSurfer is done if you find the recon-surf.done file in scripts dir. Now I have no idea why mris_sample_parc fails (non-cortex vertices with labels 43). probably something went wrong earlier. Can you try another subject?

vinkirk commented 4 years ago

I'm getting the same type of error with a different subject. These subjects have bigger ventricles and I utilize the big ventricles flag when processing these scans in FreeSurfer. I don't know if ventricular size has any bearing on this problem.

=========== Creating surfaces lh - map input seg to surf ===============

mris_sample_parc -ct /home/vinny/Tools/freesurfer/average/colortable_desikan_killiany.txt -file ./lh.DKTatlaslookup.txt -projmm 0.6 -f 5 -surf white.preaparc subj2 lh aparc+aseg.orig.mgz aparc.mapped.prefix.annot embedding color table /home/vinny/Tools/freesurfer/average/colortable_desikan_killiany.txt into output annot file using as translation fname projecting 0.60 mm along surface normal applying mode filter 5 times to parcellation using white.preaparc as surface name reading parcellation volume from /home/vinny/Tools/fastsurfer/subj2/mri/aparc+aseg.orig.mgz... reading input surface /home/vinny/Tools/fastsurfer/subj2/surf/lh.white.preaparc... pass 1: 2879 segments changed pass 2: 747 segments changed pass 3: 661 segments changed pass 4: 660 segments changed pass 5: 659 segments changed pass 6: 661 segments changed pass 7: 660 segments changed pass 8: 661 segments changed pass 9: 659 segments changed pass 10: 661 segments changed pass 11: 660 segments changed mode filtering sample labels... iter 0: 6698 changed, 57335 zero iter 1: 3386 changed, 53680 zero iter 2: 2347 changed, 51936 zero iter 3: 1896 changed, 50856 zero iter 4: 1624 changed, 49662 zero writing annotation to aparc.mapped.prefix.annot... @#@FSTIME 2020:08:21:17:20:00 mris_sample_parc N 14 e 23.72 S 8.74 U 14.96 P 99% M 12237952 F 13 R 10419763 W 0 c 102 w 17 I 3368 O 1832 L 1.08 1.09 1.15 @#@FSLOADPOST 2020:08:21:17:20:24 mris_sample_parc N 14 1.12 1.10 1.15 python3.6 smooth_aparc.py --insurf /home/vinny/Tools/fastsurfer/subj2/surf/lh.white.preaparc --inaparc /home/vinny/Tools/fastsurfer/subj2/label/lh.aparc.mapped.prefix.annot --incort /home/vinny/Tools/fastsurfer/subj2/label/lh.cortex.label --outaparc /home/vinny/Tools/fastsurfer/subj2/label/lh.aparc.mapped.annot Reading in surface: /home/vinny/Tools/fastsurfer/subj2/surf/lh.white.preaparc ... Reading in annotation: /home/vinny/Tools/fastsurfer/subj2/label/lh.aparc.mapped.prefix.annot ... Reading in cortex label: /home/vinny/Tools/fastsurfer/subj2/label/lh.cortex.label ... Non-cortex vertices with labels: 116 Command terminated by signal 11 @#@FSTIME 2020:08:21:17:20:24 python3.6 N 9 e 0.86 S 0.02 U 0.56 P 67% M 88364 F 2 R 22270 W 0 c 3 w 17 I 304 O 0 L 1.12 1.10 1.15 @#@FSLOADPOST 2020:08:21:17:20:24 python3.6 N 9 1.12 1.10 1.15 Command exited with non-zero status 1 @#@FSTIME 2020:08:21:16:58:49 /home/vinny/Tools/fastsurfer/subj2/scripts/lh.processing.cmdf N 0 e 1295.78 S 11.44 U 1284.09 P 99% M 12237952 F 194 R 12863774 W 0 c 5409 w 3217 I 46328 O 135120 L 1.05 1.25 1.42 @#@FSLOADPOST 2020:08:21:17:20:24 /home/vinny/Tools/fastsurfer/subj2/scripts/lh.processing.cmdf N 0 1.12 1.10 1.15

vinkirk commented 4 years ago

I also tested using the open-source IXI dataset and get the same error.

=========== Creating surfaces lh - map input seg to surf ===============

mris_sample_parc -ct /home/vinny/Tools/freesurfer/average/colortable_desikan_killiany.txt -file ./lh.DKTatlaslookup.txt -projmm 0.6 -f 5 -surf white.preaparc IXI lh aparc+aseg.orig.mgz aparc.mapped.prefix.annot embedding color table /home/vinny/Tools/freesurfer/average/colortable_desikan_killiany.txt into output annot file using as translation fname projecting 0.60 mm along surface normal applying mode filter 5 times to parcellation using white.preaparc as surface name reading parcellation volume from /home/vinny/Tools/fastsurfer/IXI/mri/aparc+aseg.orig.mgz... reading input surface /home/vinny/Tools/fastsurfer/IXI/surf/lh.white.preaparc... pass 1: 4186 segments changed pass 2: 31 segments changed pass 3: 10 segments changed pass 4: 10 segments changed pass 5: 10 segments changed pass 6: 10 segments changed pass 7: 10 segments changed pass 8: 10 segments changed pass 9: 10 segments changed pass 10: 10 segments changed pass 11: 10 segments changed mode filtering sample labels... iter 0: 2643 changed, 2318 zero iter 1: 1773 changed, 2129 zero iter 2: 1494 changed, 2180 zero iter 3: 1328 changed, 2194 zero iter 4: 1239 changed, 2225 zero writing annotation to aparc.mapped.prefix.annot... @#@FSTIME 2020:08:21:19:46:10 mris_sample_parc N 14 e 35.64 S 7.27 U 11.51 P 52% M 15446812 F 20914 R 5650489 W 0 c 1633 w 21676 I 297064 O 2072 L 1.00 1.27 1.30 @#@FSLOADPOST 2020:08:21:19:46:46 mris_sample_parc N 14 2.63 1.66 1.43 python3.6 smooth_aparc.py --insurf /home/vinny/Tools/fastsurfer/IXI/surf/lh.white.preaparc --inaparc /home/vinny/Tools/fastsurfer/IXI/label/lh.aparc.mapped.prefix.annot --incort /home/vinny/Tools/fastsurfer/IXI/label/lh.cortex.label --outaparc /home/vinny/Tools/fastsurfer/IXI/label/lh.aparc.mapped.annot Reading in surface: /home/vinny/Tools/fastsurfer/IXI/surf/lh.white.preaparc ... Reading in annotation: /home/vinny/Tools/fastsurfer/IXI/label/lh.aparc.mapped.prefix.annot ... Reading in cortex label: /home/vinny/Tools/fastsurfer/IXI/label/lh.cortex.label ... Non-cortex vertices with labels: 253 Command terminated by signal 11 @#@FSTIME 2020:08:21:19:46:46 python3.6 N 9 e 1.49 S 0.10 U 0.80 P 61% M 91432 F 267 R 22580 W 0 c 13 w 1034 I 135680 O 0 L 2.63 1.66 1.43 @#@FSLOADPOST 2020:08:21:19:46:48 python3.6 N 9 2.50 1.65 1.43 Command exited with non-zero status 1 @#@FSTIME 2020:08:21:19:41:19 /home/vinny/Tools/fastsurfer/IXI/scripts/lh.processing.cmdf N 0 e 328.30 S 9.44 U 301.33 P 94% M 15446812 F 21484 R 7556719 W 0 c 3398 w 25518 I 491072 O 137264 L 1.01 1.72 1.42 @#@FSLOADPOST 2020:08:21:19:46:48 /home/vinny/Tools/fastsurfer/IXI/scripts/lh.processing.cmdf N 0 2.50 1.65 1.43

vinkirk commented 4 years ago

In terms of requirements I installed the following modules:

h5py 2.10.0 nibabel 3.0.0 numpy 1.17.4 scipy 1.3.1 skimage 0.16.2 torch 1.4.0 torchvision 0.5.0

m-reuter commented 4 years ago

The requirements are in the requirements.txt file. Especially your nibabel is too new.

At some point there was a problem with newer nibabel packages, which I thought we had fixed here 9eff39ff94c407748cf3d5f5f860fe3c1fb07fc2

  1. make sure you are not working with an old version of FastSurfer (pull the most recent one) and try again

  2. if that does not fix your problem, let us know here and try with an older nibabel package as listed in the requirements.txt Thanks

vinkirk commented 4 years ago

Thanks for your guidance. I'll provide an update once I've made the changes you've recommended.

vinkirk commented 4 years ago

I get the same error...I've uploaded the recon-surf.log for your review. The same scan was completely processed in freesurfer. Thanks. recon-surf.log

m-reuter commented 4 years ago

Is this with downgraded nibabel package or only with the most recent fastsurfer, but still the newer nibabel?

Also is this an MRI that you can share for us to take a look? I can send you a way to upload via file drop (best if you send the full processed directory plus input file, in case it does not replicate here).

LeHenschel commented 4 years ago

Hey Vinny,

to see if this is still the same problem from 9eff39f you could take a look at mri/aseg.auto_noCCseg.mgz in Freeview. If the cortex is not correctly labeled (everything labeled as 255) then this is the same error as before.

However, from the recon-surf.log you shared it looks like you are using the FreeSurfer dev version (freesurfer-local-build-dev-20191106). FastSurfer should be run with FreeSurfer v6.0. This might also be a reason why the processing fails. You can either try running with a local install of FreeSurfer v6.0 or use the docker to see if the problem persists.

Best, Leonie

vinkirk commented 4 years ago

Thanks for your responses. @LeHenschel: I looked at the aseg.auto_noCCseg.mgz file and everything seems appropriately labeled. I'm downloading FreeSurfer v6.0 and will retry the processing. @m-reuter: if the problem persists, i'll upload the processed files.

Vinny

vinkirk commented 4 years ago

Unfortunately, I am getting the same error message with another scan. @m-reuter: if you can send me a way to file drop, I can send the full processed directory and input T1.

Thanks,

Vinny

LeHenschel commented 4 years ago

Hey Vinny,

what exactly did you change between the runs? Most importantly, is this with FreeSurfer 6.0 or still the dev version?

Best, Leonie

vinkirk commented 4 years ago

Hey Leonie,

I ran this with the stable FreeSurfer 6.0 and with a couple of scans but get the same error. I've attached the recon-surf.log.

Thanks,

Vinny recon-surf.log

LeHenschel commented 4 years ago

ok, thanks. I sent you an email with a link for the file drop.

vinkirk commented 4 years ago

@LeHenschel: I didn't receive the link. I've uploaded the processed files, including the T1 to github.... https://github.com/vinkirk/public/tree/master/outputs

the scan is from the IXI open-source dataset.

thanks for your help,

Vinny

LeHenschel commented 4 years ago

Hey Vinny,

I downloaded the data but can not reproduce the error (even with the same module versions you posted above). The intermediate files look fine as well. Could you run just the last command on your machine to see if you get a bit more information about the error:

cd /home/vinny/Tools/FastSurfer-git/recon_surf

python3.6 smooth_aparc.py --insurf /home/vinny/Tools/FastSurfer-git/outputs/IXI/surf/lh.white.preaparc --inaparc /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.aparc.mapped.prefix.annot --incort /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.cortex.label --outaparc /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.aparc.mapped.annot

The output should look like this:

Reading in surface: /data/surf/lh.white.preaparc ... Reading in annotation: /data/label/lh.aparc.mapped.prefix.annot ... Reading in cortex label: /data/label/lh.cortex.label ... Non-cortex vertices with labels: 268 Fill Round: 1 rows: 658 reduced to 409 Fill Round: 2 rows: 249 reduced to 193 Fill Round: 3 rows: 56 reduced to 52 Fill Round: 4 rows: 4 reduced to 4 rows: 132501 reduced to 17262 rows: 132501 reduced to 7826 Outputing fixed annot: /data/label/lh.aparc.mapped.annot

Thanks, Leonie

vinkirk commented 4 years ago

Hi Leonie,

Thanks for testing out the dataset. I tried your command but get the following message:

vinny@vinny-linux:~/Tools/FastSurfer-git/recon_surf$ python3.6 smooth_aparc.py --insurf /home/vinny/Tools/FastSurfer-git/outputs/IXI/surf/lh.white.preaparc --inaparc /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.aparc.mapped.prefix.annot --incort /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.cortex.label --outaparc /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.aparc.mapped.annot Reading in surface: /home/vinny/Tools/FastSurfer-git/outputs/IXI/surf/lh.white.preaparc ... Reading in annotation: /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.aparc.mapped.prefix.annot ... Reading in cortex label: /home/vinny/Tools/FastSurfer-git/outputs/IXI/label/lh.cortex.label ... Non-cortex vertices with labels: 268 Segmentation fault (core dumped)

LeHenschel commented 4 years ago

Hey Vinny,

given the error, it is most likely a memory problem. It's a bit hard to tell why this is happening as we can not reproduce it here.

  1. Which OS are you on and how much RAM do you have available?
  2. Have you tried the docker?

Best, Leonie

m-reuter commented 3 years ago

Closing due to inactivity, probably non enough memory or still wrong dependencies. Docker would check if it's the second.