BioMedIA / deepali

Image, point set, and surface registration in PyTorch.
https://biomedia.github.io/deepali/
Apache License 2.0
26 stars 6 forks source link

Reading file problem when running registration in parallel #88

Closed MengyunQ closed 1 year ago

MengyunQ commented 1 year ago

When I run several registration codes for a big dataset in parallel, it had this error: RuntimeError: Exception thrown in SimpleITK ImageFileReader_ReadImageInformation: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:105: sitk::ERROR: Unable to determine ImageIO reader for "seg_sa_36.nii.gz"

Would it be possible that the code had conflicts when Deepali was reading images at the same time? Because:

  1. I run several codes in parallel
  2. the error always occurred in the middle procedure, not at the start
  3. the error happened at the different subject when I rerun the code to the same set of subjects
aschuh-hf commented 1 year ago

Indeed, there seems to have been an issue in ITK with multiprocessing and the image reader.

https://discourse.itk.org/t/itk-5-2-rc2-solved-a-multiprocessing-issue-thanks/3882

For .mha (the file format we use), I am using specific MetaImage Python code to read images instead of SimpleITK actually. I was already thinking it may be good to replace SimpleITK with nibabel maybe for NIfTI rather, which is also a more lightweight dependency than SimpleITK.

Would you be interested to try and support nibabel instead as image reader for NIfTI files?

In Image.read() to call a deepali.data.image.read_image() function which returns a Grid and data Tensor. This new function could use nibabel for file paths having a NIfTI extension, a different reader I have for .mha (MetaImage) files, and otherwise fall back to using SimpleITK (deepali.utils.sitk.imageio.read_image()).

aschuh-hf commented 1 year ago

You can also try with the latest SimpleITK version (2.2.1) first, or use itk>=5.2 instead.

SimpleITK 2.2.1 uses ITK 5.3, which should include the fix (https://github.com/SimpleITK/SimpleITK/releases/tag/v2.2.1).

aschuh-hf commented 1 year ago

Hi @MengyunQ, just to confirm, which version of SimpleITK were you using when you encountered this issue? Is the issue resolved when upgrading to SimpleITK 2.2?

I now implemented NIfTI image read/write functions using nibabel as an alternative (#92). Just wondering if your issue was addressed already by a newer SimpleITK version.

aschuh-hf commented 1 year ago

Hi @MengyunQ, you noted that you were already using SimpleITK 2.2.1 when you encountered this issue. Have you been able to try the new deepali version with nibabel instead of SimpleITK for reading NIfTI images in multiple processes? Did this resolve the issue?

MengyunQ commented 1 year ago

I'm sorry for not getting back to you sooner. The SimpleITK version is 2.2.1 in my environment. I've tried running new experiments today in parallel, and the problem didn't occur. Thank you very much.

aschuh-hf commented 1 year ago

Great, thanks for giving it another try. Let me know if the issue re-occurs.