在Python中运行Nipype工作流时获取“itk::ImageFileReaderException”

2024-04-29 12:17:59 发布

您现在位置:Python中文网/ 问答频道 /正文

您好
我正在尝试跟随这个documentation。但是,在执行给定示例代码的最后一个命令后,会发生分段错误。按照说明,我已按照BIDS文件格式安装了所有必要的依赖项。
以下是数据集的组织:

data
└── sub_001
    └── session_1
        └── anat_1
            └── mr_img.nii.gz


以下是我试图执行的代码:

import os

from hansel import Crumb
from neuro_pypes.run import run_debug, run_wf
from neuro_pypes.config import update_config
from neuro_pypes.io import build_crumb_workflow
from neuro_pypes.anat import attach_spm_anat_preprocessing

base_dir = "/home/noobron/rough/mri_pre_process/data"

config_file_path = "pypes_config.yml"

data_path = os.path.join(base_dir, "{subject_id}", "session_1", "{modality}", "{image}")

data_crumb = Crumb(data_path, ignore_list=[".*"])
print(data_crumb)
print(data_crumb['subject_id'])  # ['sub_001']

attach_functions = {"spm_anat_preproc": attach_spm_anat_preprocessing}

crumb_arguments = {'anat': [('modality', 'anat_1'),
                            ('image', 'mr_img.nii.gz')]
                  }

update_config(config_file_path)

output_dir = os.path.join(os.path.dirname(base_dir), "out")
cache_dir  = os.path.join(os.path.dirname(base_dir), "wd")

wf = build_crumb_workflow(attach_functions,
                          data_crumb=data_crumb,
                          in_out_kwargs=crumb_arguments,
                          output_dir=output_dir,
                          cache_dir=cache_dir,)

run_wf(wf, plugin="MultiProc", n_cpus=8) # 'itk::ImageFileReaderException' occurs after execution of this statement. 


我已经检查了run_wf(wf, plugin="MultiProc", n_cpus=8)之前的所有语句。它们似乎都工作得很好,没有任何问题。
这是与崩溃相关联的日志文件:

Node: main_workflow.spm_anat_preproc.bias_correction
Working directory: /home/noobron/rough/mri_pre_process/wd/main_workflow/spm_anat_preproc/_subject_id_sub_001/bias_correction


Node inputs:

args = <undefined>
bias_image = <undefined>
bspline_fitting_distance = 300.0
bspline_order = <undefined>
convergence_threshold = 1e-06
copy_header = False
dimension = 3
environ = {'NSLOTS': '1'}
histogram_sharpening = <undefined>
input_image = <undefined>
mask_image = <undefined>
n_iterations = [50, 50, 30, 20]
num_threads = 1
output_image = <undefined>
rescale_intensities = False
save_bias = True
shrink_factor = 3
weight_image = <undefined>



Traceback: 
Traceback (most recent call last):
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/pipeline/plugins/multiproc.py", line 148, in __init__
    mp_context=mp_context,
TypeError: __init__() got an unexpected keyword argument 'initializer'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run
    result = self._run_interface(execute=True)
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_interface
    return self._run_command(execute)
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 741, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 434, in run
    runtime = self._run_interface(runtime)
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 829, in _run_interface
    self.raise_exception(runtime)
  File "/home/noobron/.local/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 760, in raise_exception
    ).format(**runtime.dictcopy())
RuntimeError: Command:
N4BiasFieldCorrection --bspline-fitting [ 300 ] -d 3 --input-image /home/noobron/rough/mri_pre_process/data/sub_001/session_1/anat_1/mr_img.nii.gz --convergence [ 50x50x30x20, 1e-06 ] --output [ mr_img_corrected.nii.gz, mr_img_bias.nii.gz ] --shrink-factor 3
Standard output:

Standard error:
Exception caught during reference file reading 

itk::ImageFileReaderException (0x559a5b6cba30)
Location: "unknown" 
File: /home/noobron/Downloads/install-ants/build/staging/include/ITK-5.2/itkImageFileReader.hxx
Line: 133
Description:  Could not create IO object for reading file /home/noobron/rough/mri_pre_process/data/sub_001/session_1/anat_1/mr_img.nii.gz
  Tried to create one of the following:
    BMPImageIO
    BioRadImageIO
    Bruker2dseqImageIO
    GDCMImageIO
    GE4ImageIO
    GE5ImageIO
    GiplImageIO
    HDF5ImageIO
    JPEGImageIO
    JPEG2000ImageIO
    LSMImageIO
    MGHImageIO
    MINCImageIO
    MRCImageIO
    MetaImageIO
    NiftiImageIO
    NrrdImageIO
    PNGImageIO
    StimulateImageIO
    TIFFImageIO
    VTKImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.


 file /home/noobron/rough/mri_pre_process/data/sub_001/session_1/anat_1/mr_img.nii.gz
Segmentation fault (core dumped)
Return code: 139

这是由于某个文件扩展名出现问题或配置中存在某种冲突所致。我对Nipype和它的工作流程有点陌生,如果有人能帮助解决这个问题,那将非常有帮助。
谢谢阅读。

这是项目的文件结构(以防万一)

.
├── ./data
│   └── ./data/sub_001
│       └── ./data/sub_001/session_1
├── ./neuro_pype_test.ipynb
├── ./pypes_config.yml
└── ./wd
    └── ./wd/main_workflow
        ├── ./wd/main_workflow/d3.js
        ├── ./wd/main_workflow/graph1.json
        ├── ./wd/main_workflow/graph.json
        ├── ./wd/main_workflow/index.html
        ├── ./wd/main_workflow/log
        ├── ./wd/main_workflow/spm_anat_preproc
        └── ./wd/main_workflow/_subject_id_sub_001


Tags: pathruninimagehomedatamaindir