BrainLesion / preprocessing

preprocessing tools for multi-modal 3D brain MRI
GNU Affero General Public License v3.0
11 stars 3 forks source link

No such file or directory when running preprocessing_tutorial.ipynb locally #72

Closed LennartPhil closed 4 months ago

LennartPhil commented 5 months ago

Describe the bug When trying to run the preprocessing_tutorial.ipynb I get a FileNotFoundError, which reads [Errno 2] No such file or directory: Path('/Users/XXXXXXXXX/Desktop/Uni/Prowiss/Code/preprocessing/temporary_directory/atlas-space/atlas__t1c.nii.gz')

Expected behavior As I used the exact same files from the tutorial, I expected the test files to get preprocessed as described in there.

Environment

operating system and version?

mac OS Sonoma 14.3.1

NVIDIA drivers and GPUs

no NVIDIA drivers installed

Python environment and version?

running a virtual environment with python 3.11 installed

version of brainles_preprocessing ?

0.1.1

Additional context I think I have roughly located the location of the error within the preprocessor.py file, as self.center_modality.current can't be found after the following lines

    print("Check 03")
    print("Checking existence of directory:", self.center_modality.current)
    print("Directory exists:", os.path.exists(self.center_modality.current))

    # Register center modality to atlas
    center_file_name = f"atlas__{self.center_modality.modality_name}"
    transformation_matrix = self.center_modality.register(
        registrator=self.registrator,
        fixed_image_path=self.atlas_image_path,
        registration_dir=self.atlas_dir,
        moving_image_name=center_file_name,
    )

    print("Check 04")
    print("Checking existence of directory:", self.center_modality.current)
    print("Directory exists:", os.path.exists(self.center_modality.current))

Output: Check 03 Checking existence of directory: /Users/XXXXXXXXX/Desktop/Uni/Prowiss/Code/preprocessing/sample_data/TCGA-DU-7294/AX_T1_POST_GD_FLAIR_TCGA-DU-7294_TCGA-DU-7294_GE_TCGA-DU-7294_AX_T1_POST_GD_FLAIR_RM_13_t1c.nii.gz Directory exists: True Check 04 Checking existence of directory: /Users/XXXXXXXXX/Desktop/Uni/Prowiss/Code/preprocessing/temporary_directory/atlas-space/atlas__t1c.nii.gz Directory exists: False

neuronflow commented 5 months ago

Thanks for your interest in our preprocessing pipeline. Could you specify a bit where exactly the tutorial crashes? Which registration backend do you use?

Do you have an Intel or ARM based Mac?

@MarcelRosier could you please have a look? Might be related to: https://github.com/BrainLesion/HD-BET/issues/1

LennartPhil commented 4 months ago

I'm trying to run the code on a Apple M3 Pro chip. What exactly do you mean by registration backend?

neuronflow commented 4 months ago

Ah this is probably the issue:

   preprocessor = Preprocessor(
            center_modality=center,
            moving_modalities=moving_modalities,
            registrator=NiftyRegRegistrator(),
            brain_extractor=HDBetExtractor(),
            # optional: we provide a temporary directory as a sandbox for the preprocessin
            temp_folder="temporary_directory",
            limit_cuda_visible_devices="0",
        )

Here, you can specify the registration backend:

             registrator=NiftyRegRegistrator(),

Niftyreg does not have Mac support. You could try ANTs or eReg(experimental).

So instead, supply another registrator:

from brainles_preprocessing.registration import (
    ANTsRegistrator,
    NiftyRegRegistrator,
    eRegRegistrator,
)

...

            # choose the registration backend you want to use
            # registrator=NiftyRegRegistrator(),
            registrator=ANTsRegistrator(),
            # registrator=eRegRegistrator(),

@evamariie could you please update the tutorial to tell users about the different registration backends?

Arguably, ANTs should be the default for the moment as it does not only support Linux like Niftyreg. And eReg is not fully tested yet.

neuronflow commented 4 months ago

@evamariie Also, the readme needs to be updated, please prepare a PR :) https://github.com/BrainLesion/preprocessing?tab=readme-ov-file#registration

LennartPhil commented 4 months ago

Thank you for your help, changing the registrator to ANTs worked wonderfully. It might also be worth noting that when using HDBetExtractor on a arm processor, one must set the device to "cpu"

neuronflow commented 4 months ago

Thank you for your help, changing the registrator to ANTs worked wonderfully. It might also be worth noting that when using HDBetExtractor on a arm processor, one must set the device to "cpu"

Sweet, thanks for reporting back. Did you try with the most recent version of our package? Above you are indicating an older version.

@MarcelRosier recently implemented a fix, which should fix the CPU issue: https://github.com/BrainLesion/HD-BET/pull/2

LennartPhil commented 4 months ago

My bad, using the newest version resolved the cpu workaround as well

neuronflow commented 4 months ago

Sweet, thanks for reporting back, and I'm glad everything could be resolved. We highly appreciate feedback as we are still in an earlier stage of development :)