MIC-DKFZ / TractSeg

Automatic White Matter Bundle Segmentation
Apache License 2.0
226 stars 76 forks source link

No such file or no access: 'tractseg_output/peaks.nii.gz' #1

Closed soichih closed 6 years ago

soichih commented 6 years ago

Hello!

I am trying to run TractSeg via singularity like the following

singularity exec -e docker://gkoehler90/tractseg TractSeg -i dwi.nii.gz

I have following files in my local directory.

hayashis@xps15:~/test/tractseg $ ls -lrt
total 1461344
-rw-r--r-- 1 hayashis hayashis       9507 Jun 25 13:26 dwi.bvecs
-rw-r--r-- 1 hayashis hayashis       1631 Jun 25 13:26 dwi.bvals
-rw-r--r-- 1 hayashis hayashis 1496386061 Jun 25 13:26 dwi.nii.gz

When I run it, I get following error messages.

Loading weights from: /home/hayashis/.tractseg/pretrained_weights_tract_segmentation_v1.npz
Creating brain mask...
sh: 1: bet: not found
rm: cannot remove 'tractseg_output/nodif_brain_mask.nii.gz': No such file or directory
mv: cannot stat 'tractseg_output/nodif_brain_mask_mask.nii.gz': No such file or directory
Creating peaks (1 of 3)...
sh: 1: dwi2response: not found
Creating peaks (2 of 3)...
sh: 1: dwi2fod: not found
Creating peaks (3 of 3)...
sh: 1: sh2peaks: not found
Traceback (most recent call last):
  File "/usr/local/bin/TractSeg", line 137, in <module>
    data_img = nib.load(join(HP.PREDICT_IMG_OUTPUT, "peaks.nii.gz"))
  File "/usr/local/lib/python2.7/dist-packages/nibabel/loadsave.py", line 42, in load
    raise FileNotFoundError("No such file or no access: '%s'" % filename)
nibabel.py3k.FileNotFoundError: No such file or no access: 'tractseg_output/peaks.nii.gz'

On my current directory, I see an empty directory created with the name "tracseg_output".

hayashis@xps15:~/test/tractseg 1 ls -la
total 1461356
drwxrwxr-x  3 hayashis hayashis       4096 Jun 25 13:31 .
drwxrwxr-x 46 hayashis hayashis       4096 Jun 25 12:15 ..
-rw-r--r--  1 hayashis hayashis       1631 Jun 25 13:26 dwi.bvals
-rw-r--r--  1 hayashis hayashis       9507 Jun 25 13:26 dwi.bvecs
-rw-r--r--  1 hayashis hayashis 1496386061 Jun 25 13:26 dwi.nii.gz
drwxrwxr-x  2 hayashis hayashis       4096 Jun 25 13:31 tractseg_output
hayashis@xps15:~/test/tractseg $ ls -a tractseg_output/
.  ..

Am I running this in a wrong way?

wasserth commented 6 years ago

The docker container provided in the repository is still work in progress (WIP). It does not work yet, because the FSL and Mrtrix commands are not automatically loaded (.bashrc is not automatically sourced). Apart from that the docker container is ready. I will try to fix this issue soon. If you do not want to wait you can use TractSeg without Docker. That works.

wasserth commented 6 years ago

I just realized you are using the docker container from gkoehler90/tractseg. That one is out-dated. As soon as I fixed the docker issue mentioned in the previous comment I will push a new docker image to dockerhub. Until then you should use TractSeg without Docker (or build your own docker container).

soichih commented 6 years ago

@wasserth Thank you for looking into the container issue. I did try to run it without it by installing various dependencies, but I couldn't get it to work after messing around for a while. I can wait for the container to be updated.

wasserth commented 6 years ago

@soichih I fixed the issues and now it should work using the following command:

sudo docker run -v /absolute/path/to/my/data/directory:/data \
-t wasserth/tractseg_container:v1.4 TractSeg -i /data/dwi.nii.gz -o /data

On OSX you might have to increase the Docker Memory limit from the default of 2GB to something higher.

soichih commented 6 years ago

Great! Thanks!

I just tested it again (I have to use singularity for our HPC system)

$ singularity exec docker://wasserth/tractseg_container:v1.4 TractSeg -i dwi.nii.gz
...
Creating brain mask...
sh: 1: bet: not found
rm: cannot remove 'tractseg_output/nodif_brain_mask.nii.gz': No such file or directory
mv: cannot stat 'tractseg_output/nodif_brain_mask_mask.nii.gz': No such file or directory
Creating peaks (1 of 3)...
dwi2response: [ERROR] Command failed: mrconvert /home/hayashis/test/tractseg/tractseg_output/nodif_brain_mask.nii.gz /home/hayashis/test/tractseg/dwi2response-tmp-WJAF5I/mask.mif -datatype bit (dwi2response:88)
dwi2response: Output of failed command:
              mrconvert: [ERROR] cannot access file "/home/hayashis/test/tractseg/tractseg_output/nodif_brain_mask.nii.gz": No such file or directory
              mrconvert: [ERROR] error opening image "/home/hayashis/test/tractseg/tractseg_output/nodif_brain_mask.nii.gz"
dwi2response: Script failed while executing the command: mrconvert /home/hayashis/test/tractseg/tractseg_output/nodif_brain_mask.nii.gz /home/hayashis/test/tractseg/dwi2response-tmp-WJAF5I/mask.mif -datatype bit
dwi2response: For debugging, inspect contents of temporary directory: /home/hayashis/test/tractseg/dwi2response-tmp-WJAF5I/
Creating peaks (2 of 3)...
dwi2fod: [ERROR] cannot access file "tractseg_output/nodif_brain_mask.nii.gz": No such file or directory
dwi2fod: [ERROR] error opening image "tractseg_output/nodif_brain_mask.nii.gz"
Creating peaks (3 of 3)...
sh2peaks: [ERROR] failed to open key/value file "tractseg_output/WM_FODs.mif": No such file or directory
sh2peaks: [ERROR] error opening image "tractseg_output/WM_FODs.mif"
Traceback (most recent call last):
  File "/usr/local/bin/TractSeg", line 113, in <module>
    data_img = nib.load(join(HP.PREDICT_IMG_OUTPUT, "peaks.nii.gz"))
  File "/usr/local/lib/python2.7/dist-packages/nibabel/loadsave.py", line 42, in load
    raise FileNotFoundError("No such file or no access: '%s'" % filename)
nibabel.py3k.FileNotFoundError: No such file or no access: 'tractseg_output/peaks.nii.gz'
...

Maybe FSL is not in the PATH?

wasserth commented 6 years ago

When I run the docker container FSL is in the PATH. So it is strange that it does not find it when you run it with singularity. I updated the python code so FSL is added to the path right before "bet" is called. So you could try it again. I updated the container on dockerhub (version is still v.1.4, so you might have to deleted your downloaded image first so it will download the new one)

soichih commented 6 years ago

I've cleaned the ~/.singularity/docker directory and rerun, but I am still seeing the same error message.

Creating brain mask...
sh: 1: bet: not found
rm: cannot remove 'tractseg_output/nodif_brain_mask.nii.gz': No such file or directory
mv: cannot stat 'tractseg_output/nodif_brain_mask_mask.nii.gz': No such file or directory
Creating peaks (1 of 3)...

I've also tried running singularity witih -e option which prevents ENV parameter on the host to be set inside the container, but that didn't help either. I think the issue is related to singularity but I haven't really looked into it yet.

wasserth commented 6 years ago

Sorry for the late reply. I was on vacation last week. I also think it is an issue with singularity as it works fine with plain Docker on several systems. I never used singularity so I do not know about its details.

soichih commented 6 years ago

OK. I've created my own Dockerfile that works for our environment. Tractseg now seems to work via singularity!

The first thing I noticed though, is that it's downloading the trained model under $HOME/.tractseg. Is there anyway I could pre-stage the model and make it part of my Docker container? - maybe by doing something like RUN curl http:/somewhere/pretrained_weights_tract_segmentation -O someplace and point Tractseg to use it?

nvm.. I found this on the official Dockerfile

RUN mkdir -p ~/.tractseg \
    && curl -SL -o ~/.tractseg/pretrained_weights_tract_segmentation_v1.npz https://www.dropbox.com/s/nygr0j2zgztedh0/TractSeg_best_weights_ep448.npz?dl=1 \
    && curl -SL -o ~/.tractseg/pretrained_weights_endings_segmentation_v2.npz https://www.dropbox.com/s/l5fa6hhtbv5npvm/EndingsSeg_best_weights_ep176.npz?dl=1 \
    && curl -SL -o ~/.tractseg/pretrained_weights_peak_regression_v1.npz https://www.dropbox.com/s/ogywkbrj3165v3e/PeakReg_best_weights_ep229.npz?dl=1 \
&& curl -SL -o ~/.tractseg/pretrained_weights_dm_regression_v1.npz https://www.dropbox.com/s/d82iv95flz8n5a2/DmReg_best_weights_ep427.npz?dl=1
wasserth commented 6 years ago

Great that it works. So far there is not option to change the tractseg home directory from ~/.tractseg to another place. You would have to change it in the code. But I think inside of the docker container it does not really matter where those weights are located. So ~/.tractseg should be fine normally.

soichih commented 6 years ago

I am running it through singularity, and it mounts host's home directory by default - wiping out the container's home directory (/root for docker?).

I've done following to hack around it.

export HOME=/
TractSeg -i $dwi  -o .

It's ugly.. but it seems to work for now. It would be nice to be able to specify the directory where model is stored though! :)