QSIPrep MRI_Synthstrip failing

Summary of what happened:

I’m running QSIPrep on a single subject/session. The workflow reaches the b0 template mask step and calls mri_synthstrip on the averaged b0 image, but SynthStrip errors with ValueError: attempt to get argmax of an empty sequence.

Command used (and if a helper script was used, a link to the helper script or the command generated):

docker run -it --rm \
  -v "/mnt/v/qsi_pipeline/bids:/data:ro" \
  -v "/mnt/v/qsi_pipeline/qsiprep_out:/out" \
  -v "$HOME/qsiprep_work:/work" \
  -v "/mnt/c/Users/MY_USER/Desktop/license.txt:/license.txt:ro" \
  -e FS_LICENSE=/license.txt \
  -e MKL_NUM_THREADS=1 \
  -e OPENBLAS_NUM_THREADS=1 \
  -e OMP_NUM_THREADS=1 \
  --user 0:0 \
  pennlinc/qsiprep:unstable \
  /data /out participant \
  --participant-label 01 \
  --anat-modality T1w \
  --subject-anatomical-reference sessionwise \
  --nprocs 15 \
  --omp-nthreads 2 \
  --output-resolution 2.0 \
  --fs-license-file /license.txt \
  --hmc-model 3dSHORE \
  --unringing-method rpg \
  -w /work \
  --separate-all-dwis

Version:

QSIPrep: pennlinc/qsiprep:unstable
FreeSurfer: 8.0.0

Environment (Docker, Singularity / Apptainer, custom installation):

Docker (running through WSL2)

Data formatted according to a validatable standard? Please provide the output of the validator:

1: [WARN] The recommended file /README is missing. See Section 03 (Modality agnostic files) of the BIDS specification. (code: 101 - README_FILE_MISSING)

Please visit https://neurostars.org/search?q=README_FILE_MISSING for existing conversations about this issue.

2: [WARN] The Authors field of dataset_description.json should contain an array of fields - with one author per field. This was triggered because there are no authors, which will make DOI registration from dataset metadata impossible. (code: 113 - NO_AUTHORS)

Please visit https://neurostars.org/search?q=NO_AUTHORS for existing conversations about this issue.

        Summary:             Available Tasks:        Available Modalities:
        7 Files, 16MB                                MRI
        1 - Subject
        1 - Session

Relevant log outputs (up to 20 lines):

Cmdline:
        mri_synthstrip -i /work/qsiprep_1_0_wf/sub_01_ses_01_wf/dwi_preproc_ses_01_wf/qsiprep_hmcsdc_wf/dwi_hmc_wf/b0_template_mask/synthstrip_wf/pad_before_synthstrip_wf/resample_skulled_to_reference/average_trans_trans.nii -o average_trans_trans_brain.nii.gz -m average_trans_trans_mask.nii.gz
Stdout:
        Configuring model on the CPU
        Running SynthStrip model version 1
        Input image read from: /work/qsiprep_1_0_wf/sub_01_ses_01_wf/dwi_preproc_ses_01_wf/qsiprep_hmcsdc_wf/dwi_hmc_wf/b0_template_mask/synthstrip_wf/pad_before_synthstrip_wf/resample_skulled_to_reference/average_trans_trans.nii
Stderr:
        RuntimeWarning: invalid value encountered in divide
        Traceback (most recent call last):
          File "/opt/freesurfer/bin/mri_synthstrip", line 232, in <module>
            mask = (components == (np.argmax(bincount) + 1))
          File "<__array_function__ internals>", line 180, in argmax
          File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 1216, in argmax
            return _wrapfunc(a, 'argmax', axis=axis, out=out, **kwds)
          File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
            return bound(*args, **kwds)
        ValueError: attempt to get argmax of an empty sequence
Traceback:
        Traceback (most recent call last):
          File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 401, in run
            runtime = self._run_interface(runtime)
          File "/opt/conda/envs/qsiprep/lib/python3.10/site-packages/qsiprep/interfaces/freesurfer.py", line 192, in _run_interface
            raise Exception('mri_synthstrip failed!')
        Exception: mri_synthstrip failed!

Screenshots / relevant information:

My b0 values are:

0 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

I had previously gotten an error with merge-dwis, which is why I switched to the unstable tag of QSIPrep. I can reply with the log for this error if it’s helpful.


Hi @wout5, and welcome to neurostars!

I have moved your post to a new topic since the post you commented on was very old. You can also see I have reformatted your post to the Software Support post category template. Please edit your post to fill out the missing information.

Best,
Steven

Hi Steven, thanks, and thank you for the quick response! I’ve edited my post to reflect the error I was running into.

Hi @wout5,

Thanks for providing that information.

How much memory are you devoting to Docker? Do you have access to a high-performance computing cluster?

Also,

why use 3dSHORE if you have shelled data?

Best,
Steven

Docker (running via WSL2) is allocated ~94 GiB of RAM and ~32 GiB of swap. At the moment, I don’t have access to a HPC cluster.

Thanks for pointing that out! I used --hmc-model 3dSHORE because I wasn’t sure what the recommended option was, but I used --hmc-model eddy and I received the same error.

Hi @wout5,

I am not sure how stable these software are on Windows.

Is this error subject-specific or do you get it for everyone in this dataset?

Can you provide a screenshot of /work/qsiprep_1_0_wf/sub_01_ses_01_wf/dwi_preproc_ses_01_wf/qsiprep_hmcsdc_wf/dwi_hmc_wf/b0_template_mask/synthstrip_wf/pad_before_synthstrip_wf/resample_skulled_to_reference/average_trans_trans.nii?

Best,
Steven

Thanks for the follow-up.

I’m getting this error for everyone in this dataset.

I checked the file you pointed to (/work/qsiprep_1_0_wf/sub_01_ses_01_wf/dwi_preproc_ses_01_wf/qsiprep_hmcsdc_wf/dwi_hmc_wf/b0_template_mask/synthstrip_wf/pad_before_synthstrip_wf/resample_skulled_to_reference/average_trans_trans.nii). Here are the stats:

  • shape: (63, 63, 64)
  • dtype: float65
  • min/max/p99: 0.0 / 0.0 / 0.0
  • scl_slope / scl_inter: NaN / NaN
  • cal_min / cal_max: 0.0 / 0.0
  • pixdim: [1. 1. 1. 1. 0. 0. 0. 0.]

When I open the image, it’s completely black, which makes sense given the stats. The volume is entirely zeros and the header scaling fields are set to NaN? It looks like the average_trans_trans.nii going into SynthStrip is invalid.

Does the raw b0 look okay?

Yes, the raw b0 looks fine. I checked the raw b0 directly from my BIDS dataset (sub-01_ses-01_dwi.nii.gz). The mid-slice looks normal and the intensity range is reasonable (0-2880).

I tried re-running this with the --dwi-only argument, too, and ran into the same issue.

Hi @wout5,

Can you try to add --no-b0-harmonization argument?

Best,
Steven

Still getting the same error, unfortunately. Is there anything else that you think could be the issue?

Did you try with a fresh working directory when you added the argument?

Yes, I cleared the old working directory and re-ran with a fresh workdir and got the same result.

Hi @Steven,

I tried running QSIPrep and QSIRecon on a few other participants, and it seems to have worked properly! The sessions for the working participants had b-values of ten 0s and sixty-four 1000s. However, the failed sessions had b-values of only one 0 and twenty 1000s. I am trying to figure out why the failed sessions are not working – could it be possible that the single b0 is causing this issue?

Similar to this thread: QSIPrep error merge_dwis

Hi @wout5,

I suppose it’s possible that it’s a bug when there’s only 1 b0, but I would imagine if that were the case we would be seeing a lot more bug reports about it since that’s a fairly common acquisition scheme. However, as a test, how about you try to append an extra b0 in the acquisition? Some example code (please test on a copy of your data, as to not accidentally ruin the original):

# inputs assumed: dwi.nii.gz, dwi.bval, dwi.bvec
in=dwi

# extract first volume (index 0) -> 1 volume
fslroi ${in}.nii.gz ${in}_b0.nii.gz 0 1

# prepend it to the original time series
fslmerge -t ${in}_dup0.nii.gz ${in}_b0.nii.gz ${in}.nii.gz

Make sure you update the testing b-val and b-vec image accordingly.

Best,
Steven

Hi @Steven,

Thanks for the reply. I went ahead and tried appending an extra b0 volume, but as you suspected, that didn’t resolve the error.

The reason I initially suspected it had to do with b0 handling is that right before SynthStrip runs, for the failed sessions, I see the following warning:

250919-14:50:07,547 nipype.workflow WARNING:
         An image has no b=0 images and cannot be harmonized

Since duplicating the b0 didn’t change the outcome, I’m wondering if the issue is less about the number of b0s and more about how they’re being defined or interpreted in my dataset. For instance, could something about the .bval formatting or metadata cause QSIPrep to treat them all as non-zero shells? Or is there another stage of the pipeline where the presence of only one b0 would still cause problems, even if it’s read correctly?

@mattcieslak any thoughts on this one?