sct-pipeline / contrast-agnostic-softseg-spinalcord

Contrast-agnostic spinal cord segmentation project with softseg
MIT License
4 stars 3 forks source link

Running into errors while using `--device gpu` while running inference using MONAI #75

Closed rohanbanerjee closed 9 months ago

rohanbanerjee commented 9 months ago

Hi,

I am running into errors while using run_inference_single_image.py under the monai folder which is now part of the main branch.

I am using the command in the format:

python run_inference.py --path-json <path/to/json> --chkp-path <path/to/checkpoint> --path-out <path/to/output> --model <unet/nnunet> --crop_size <48x160x320> --device cpu

When I am using cpu for the value of --device, the inference runs fine. But when I try to use the value as gpu, the script runs into an error mentioned below (not pasted the whole traceback, can paste if needed):

RuntimeError: applying transform <monai.transforms.post.dictionary.Invertd object at 0x7f4b4bf0c970>

To reproduce this, you can run:

python /home/GRAMES.POLYMTL.CA/robana/duke/temp/rohan/fmri_sc_seg/monai/run_inference_single_image.py --path-img /home/GRAMES.POLYMTL.CA/robana/duke/temp/rohan/fmri_sc_seg/nnUNet_raw/Dataset013_spinefmri/imagesTs/sc_superset_geneva_ss_sub-genevaR105_001_0000.nii.gz --chkp-path /home/GRAMES.POLYMTL.CA/robana/duke/temp/muena/contrast-agnostic/final_monai_model/nnunet_nf=32_DS=1_opt=adam_lr=0.001_AdapW_CCrop_bs=2_64x192x320_20230918-2253 --path-out /home/GRAMES.POLYMTL.CA/robana/duke/temp/rohan/fmri_sc_seg/results/monai_results --device gpu"

Is this a known issue?

TIA

naga-karthik commented 9 months ago

Hey, I think it's becase of the cupy package. I created a branch nk/fix-gpu-inference. There's a new requirements file for gpu inference.

Could you install those reqs and report back if it is working? thanks!

rohanbanerjee commented 9 months ago

I installed the requirement and it works as expected when gpu is used. Thanks of the quick fix!

naga-karthik commented 9 months ago

Great, thanks for confirming! 🙌