raidionics / Raidionics

Software for automatic segmentation and generation of standardized clinical reports of brain tumors from MRI volumes
https://raidionics.github.io/
BSD 2-Clause "Simplified" License
31 stars 4 forks source link

FLAIR segmentation not running for low-grade glioma mode #39

Closed natalievpj closed 6 months ago

natalievpj commented 1 year ago

Is there a specific workaround for FLAIR-based segmentation of low grade glioma? Glioblastoma on T1-ce segmentation now works well, but given FLAIR (or T1ce, or T1w) and running the segmentation mode for low-grade glioma, the segmentation does not appear to want to initialise (red circle, seems to crash, no segmentation produced). Have tried importing just the FLAIR sequence (nifti) which is automatically correctly identified as FLAIR as the Data type; and loading multiple sequences (FLAIR, T1w, T1CE). I've tried via Actions> preoperative segmentation and via Run Segmentation; and have tried multiple different patient datasets. Thanks for advice. Operating systems tried: Mac M1 Monterey and MacOS Catalina (Intel i7).

dbouget commented 1 year ago

Hi @natalievpj, There is no specific workaround for running the low-grade glioma segmentation model on FLAIR data. The process you describe seems correct, and it should work exactly like for glioblastoma use-cases.

Can you open the Logs window after an unsuccessful segmentation attempt, and copy paste the content of the window in here? You will find it in the top menu-bar, under Settings > Logs, of you can simply use the cmd(⌘) + L shortcut on Mac.

natalievpj commented 1 year ago

Good morning, thanks for the quick reply. Ah it looks like there is missing LGG_pipeline according to the logs.

Please see enclosed below (this is the M1 chip laptop version, but if I recall, this has never worked for the older laptop pre-M1 either with the earlier release version of Raidionics).

Thank you Natalie

04/05/2023 09.25 ; root ; DEBUG ; Detected primary screen size [w: 1512, h: 982] 04/05/2023 09.25 ; root ; WARNING ; Native application dimensions can't be set because of too small screen dimensions 04/05/2023 09.25 ; root ; DEBUG ; Setting application dimensions to [w: 1440, h: 982] 04/05/2023 09.25 ; root ; DEBUG ; Setting SinglePatientWidget dimensions to PySide6.QtCore.QSize(1440, 982). 04/05/2023 09.25 ; root ; DEBUG ; Setting CentralAreaWidget dimensions to PySide6.QtCore.QSize(640, 480). 04/05/2023 09.25 ; root ; DEBUG ; Setting CentralDisplayAreaWidget dimensions to PySide6.QtCore.QSize(640, 480). 04/05/2023 09.25 ; root ; DEBUG ; SinglePatientLayersWidget size set to PySide6.QtCore.QSize(640, 480). 04/05/2023 09.25 ; root ; DEBUG ; Setting StudyBatchWidget dimensions to PySide6.QtCore.QSize(1440, 982). 04/05/2023 09.25 ; root ; DEBUG ; New patient creation requested. 04/05/2023 09.25 ; root ; INFO ; Output patient directory set to: /Users/natalie/Documents/FMRIB/Tumours/Raidionics/patients/temp_patient 04/05/2023 09.25 ; root ; INFO ; Renamed current output folder to: /Users/natalie/Documents/FMRIB/Tumours/Raidionics/patients/joshua_shannon 04/05/2023 09.25 ; root ; DEBUG ; Active patient uid changed from None to 89953. 04/05/2023 09.25 ; root ; DEBUG ; Loading patient 89953 from memory. 04/05/2023 09.25 ; root ; INFO ; New data file imported: 1772_SER2_FLAIR_SENSE_20201128160100_301 04/05/2023 09.25 ; root ; DEBUG ; Unsaved changes - Patient object expanded with new volumes. 04/05/2023 09.25 ; root ; INFO ; [MRISeriesLayerWidget] Visibility toggled to True for 1772_SER2_FLAIR_SENSE_20201128160100_301 04/05/2023 09.25 ; root ; INFO ; Starting pipeline process for task: preop_segmentation. 04/05/2023 09.25 ; root ; INFO ; Starting pipeline process for patient 89953 and task preop_segmentation. 04/05/2023 09.25 ; root ; INFO ; Saving patient results in: /Users/natalie/Documents/FMRIB/Tumours/Raidionics/patients/joshua_shannon 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; Starting new HTTPS connection (1): drive.google.com:443 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; https://drive.google.com:443 "GET /uc?id=1lpy-BMqZsjjxvTzT2Qn95kG2XvN6RZ21 HTTP/1.1" 303 0 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; Starting new HTTPS connection (1): doc-00-1g-docs.googleusercontent.com:443 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; https://doc-00-1g-docs.googleusercontent.com:443 "GET /docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/or4khhcj2fb0goggg7uk1kb9u56icqnm/1683188700000/18423052431994531231//1lpy-BMqZsjjxvTzT2Qn95kG2XvN6RZ21?uuid=5eb20a68-aa5e-494a-b4ce-e9c36423c748 HTTP/1.1" 200 1016 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; Starting new HTTPS connection (1): drive.google.com:443 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; https://drive.google.com:443 "GET /uc?id=1lpy-BMqZsjjxvTzT2Qn95kG2XvN6RZ21 HTTP/1.1" 303 0 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; Starting new HTTPS connection (1): doc-00-1g-docs.googleusercontent.com:443 04/05/2023 09.25 ; urllib3.connectionpool ; DEBUG ; https://doc-00-1g-docs.googleusercontent.com:443 "GET /docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/or4khhcj2fb0goggg7uk1kb9u56icqnm/1683188700000/18423052431994531231//1lpy-BMqZsjjxvTzT2Qn95kG2XvN6RZ21?uuid=e5966812-747a-400f-aead-4c68f4945985 HTTP/1.1" 200 1016 04/05/2023 09.25 ; root ; ERROR ; Pipeline process for patient 89953, for task preop_segmentation failed with: Traceback (most recent call last): File "utils/backend_logic.py", line 101, in run_pipeline pipeline = create_pipeline(model_name, patient_parameters, task) File "utils/logic/PipelineCreationHandler.py", line 63, in create_pipeline return create_segmentation_pipeline(model_name, patient_parameters) File "utils/logic/PipelineCreationHandler.py", line 96, in create_segmentation_pipeline infile = open(os.path.join(SoftwareConfigResources.getInstance().models_path, model_name, 'pipeline.json'), 'rb') FileNotFoundError: [Errno 2] No such file or directory: '/Users/natalie/.raidionics/resources/models/MRI_LGGlioma/pipeline.json' 04/05/2023 09.25 ; root ; INFO ; Saving patient results in: /Users/natalie/Documents/FMRIB/Tumours/Raidionics/patients/joshua_shannon

From: David Bouget @.> Date: Thursday, 4 May 2023 at 08:50 To: raidionics/Raidionics @.> Cc: Natalie Voets @.>, Mention @.> Subject: Re: [raidionics/Raidionics] FLAIR segmentation not running for low-grade glioma mode (Issue #39)

Hi @natalievpjhttps://github.com/natalievpj, There is no specific workaround for running the low-grade glioma segmentation model on FLAIR data. The process you describe seems correct, and it should work exactly like for glioblastoma use-cases.

Can you open the Logs window after an unsuccessful segmentation attempt, and copy paste the content of the window in here? You will find it in the top menu-bar, under Settings > Logs, of you can simply use the cmd(⌘) + L shortcut on Mac.

— Reply to this email directly, view it on GitHubhttps://github.com/raidionics/Raidionics/issues/39#issuecomment-1534242931, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A7SYDSFUKLH6I2BSA3XJYTLXENNUTANCNFSM6AAAAAAXUY4ASQ. You are receiving this because you were mentioned.Message ID: @.***>

dbouget commented 1 year ago

The pipeline file is downloaded at the same time as the segmentation model itself. However, if a new version of Raidionics is installed, the previous models folder on disk is not being deleted and old models are likely to then be incompatible because of a caching mechanism (which is an issue we have to fix).

In order to allow for a proper re-download of all models, especially after installing a new version of the software, you have to open the Settings panel (cmd(⌘) + P), and in System settings you have to click the Models purge option (with a trash bin icon). You can then try to segment an LGG case, it might take a bit of time or freeze only showing the processing wheel with "-", which simply means that the model is being downloaded in the background.

Let me know if it fixed the problem.

natalievpj commented 1 year ago

Perfect, yes, that ‘models purge’ fixed it, thank you.

From: David Bouget @.> Date: Thursday, 4 May 2023 at 10:51 To: raidionics/Raidionics @.> Cc: Natalie Voets @.>, Mention @.> Subject: Re: [raidionics/Raidionics] FLAIR segmentation not running for low-grade glioma mode (Issue #39)

The pipeline file is downloaded at the same time as the segmentation model itself. However, if a new version of Raidionics is installed, the previous models folder on disk is not being deleted and old models are likely to then be incompatible because of a caching mechanism (which is an issue we have to fix).

In order to allow for a proper re-download of all models, especially after installing a new version of the software, you have to open the Settings panel (cmd(⌘) + P), and in System settings you have to click the Models purge option (with a trash bin icon). You can then try to segment an LGG case, it might take a bit of time or freeze only showing the processing wheel with "-", which simply means that the model is being downloaded in the background.

Let me know if it fixed the problem.

— Reply to this email directly, view it on GitHubhttps://github.com/raidionics/Raidionics/issues/39#issuecomment-1534438543, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A7SYDSCBFWR4XCBIGUPIVPDXEN3WXANCNFSM6AAAAAAXUY4ASQ. You are receiving this because you were mentioned.Message ID: @.***>

dbouget commented 1 year ago

Great!

Alternatively, you can also tick the Models update option in the Settings panel. It will force the system to check if a new model is available everytime the segmentation task is performed, and if so the latest model will be downloaded.

natalievpj commented 7 months ago

Dear David

Thanks for your help in the past.

I wondered if you could advise with some difficulty locating/manually downloading the required models when these are not found through the normal package install (or via a system models>purge)?

I recently downloaded v1.2.2 for MacOS ARM (M1 Pro running Ventura 13.3.1). This was working fine until, while making my way through a list of tumours, Raidionics did not want to accept a particular image, nor a few subsequent ones (FLAIRs). This has happened in the past when working through many patients, so I restarted Raidionics (no success).

I also tried a different tumour type (calling a T1ce) which opened ok but would not segment. The log stated it could not find the model .json. I tried the models/purge (with models update option ticked on). No success. I tried a full delete of the Raidionics icon from Apps folder and redownloading (with laptop reboot). Same issue (no model found and not fixed by a purge + resegment attempt). I used the terminal to navigate to /Users/me/.raidionics/resources/models which does not seem to have anything in it (‘ls’ returns no result). So I tried a rm -rf of .radionics there, and again a full redownload& package install (1.2.2-macOS-arm64.pkg).

Each time the software downloads ok and I can open it, but it seems cannot find the segmentation models.

The images do segment ok in version 1.2 that I have still available on an older laptop.

Is there a git pull for missing files or another solution that you might suggest trying?

Thanks so much, hope all is well

Natalie

dbouget commented 7 months ago

Hi @natalievpj,

I have just tried again the same process as you described above on an M1 machine. I've deleted the .raidionics folder and installed the latest v1.2.2. version for MacOS ARM, loaded a new FLAIR image, and ran the segmentation task, and everything worked fine.

As I can't seem to reproduce the issue, it is difficult to get an idea as to what might go wrong on your own machine. If no model is being downloaded automatically at all, it might be related to some internet, firewall, or Google Drive related issues. In that case, you can try to manually download the models as explained below. I have not ran extensive testing when having many patients opened at the same time, but you more often experience issues in such use-case compared to opening a few patients?

Simple test

If you download the provided test data sample, available through the GUI buy clicking File > Download test data, and then load the T1 MRI scan available in the Raw subfolder (might have to adjust the sequence type to T1-CE in the right-hand side panel), can you run the preoperative segmentation task for Glioblastoma?

Models manual download

All the models used by Raidionics can indeed be manually downloaded at the following link, more specifically the LGG preop segmentation model is available here. After downloading the archive, you simply need to extract the content and place the obtained folder inside ~/.raidionics/resources/models/.

FLAIR images

I have noticed some issues when the intensity range for FLAIR images is within [0, 255], as the image might be confused with an annotation mask. Was it the case for the images you had trouble segmenting? You can have a look at the intensity range/histogram by clicking the Contrast button associated with the MRI scan to the right-hand side panel of the interface.

Settings/Preferences

After deleting the ~/.raidionics folder, all user preferences should have been set to their default values. But if you open the settings panel (through cmd(⌘) + P), and navigate Processing-Segmentation > Segmentation models, if the Output classes is not set to Tumor, the multiclass model will require multiple MRI scans as input (T1-w, T1-CE, T2, and FLAIR) for running successfully over the glioblastoma/low-grade glioma tumor types.

Those are ideas/suggestions that come to mind, let me know if you manage to solve your issue!

natalievpj commented 7 months ago

Hi

Thanks very much for the response and helpful details.

Models – great thank you. I have manually downloaded these and both glioblastoma and low grade segmentation now run again. I don’t know why it fails to transfer with the original download/models purge, but manual download solved it!

Multiple patients sequentially – the behaviour reminds me a bit of a memory clearing problem. The sweet spot seems to be around 8 or 10 patients, I do them one at a time (load new patient, segment, save, close completely (don’t save), load a new patient, etc. At some point (around the 8th or 10th time or so), I find Raidionics crashes. It is either totally crashes (and closes) or it complains about an image when the image is fine (if I close Raidionics and reopen the same image then its fine). Just as user feedback.

FLAIR – I can’t check using the ‘contrast’ setting in Raidionics unfortunately because the image will never open at all (error message is ”unable to load FLAIR.nii.gz. Error message: no MRI volume has been imported yet. Mandatory for important an annotation”.). However I’ve checked the intensity range differently (fslstats) and yes absolutely - the range is 0 – 200. Another FLAIR that does open successfully has indeed a higher max value range. If you happen to implement a workaround I will gladly try again (I’ve just segmented in ITK snap for now, but have kept a note of which patients these were).

Thanks again for the help Natalie

From: David Bouget @.> Date: Wednesday, 7 February 2024 at 11:32 To: raidionics/Raidionics @.> Cc: Natalie Voets @.>, Mention @.> Subject: Re: [raidionics/Raidionics] FLAIR segmentation not running for low-grade glioma mode (Issue #39)

Hi @natalievpjhttps://github.com/natalievpj,

I have just tried again the same process as you described above on an M1 machine. I've deleted the .raidionics folder and installed the latest v1.2.2. version for MacOS ARM, loaded a new FLAIR image, and ran the segmentation task, and everything worked fine.

As I can't seem to reproduce the issue, it is difficult to get an idea as to what might go wrong on your own machine. If no model is being downloaded automatically at all, it might be related to some internet, firewall, or Google Drive related issues. In that case, you can try to manually download the models as explained below. I have not ran extensive testing when having many patients opened at the same time, but you more often experience issues in such use-case compared to opening a few patients?

Simple test

If you download the provided test data sample, available through the GUI buy clicking File > Download test data, and then load the T1 MRI scan available in the Raw subfolder (might have to adjust the sequence type to T1-CE in the right-hand side panel), can you run the preoperative segmentation task for Glioblastoma?

Models manual download

All the models used by Raidionics can indeed be manually downloaded at the following linkhttps://github.com/raidionics/Raidionics-models/releases/tag/1.2.0, more specifically the LGG preop segmentation model is available herehttps://github.com/raidionics/Raidionics-models/releases/download/1.2.0/Raidionics-MRI_LGGlioma-ONNX-v12.zip. After downloading the archive, you simply need to extract the content and place the obtained folder inside ~/.raidionics/resources/models/.

FLAIR images

I have noticed some issues when the intensity range for FLAIR images is within [0, 255], as the image might be confused with an annotation mask. Was it the case for the images you had trouble segmenting? You can have a look at the intensity range/histogram by clicking the Contrast button associated with the MRI scan to the right-hand side panel of the interface.

Settings/Preferences

After deleting the ~/.raidionics folder, all user preferences should have been set to their default values. But if you open the settings panel (through cmd(⌘) + P), and navigate Processing-Segmentation > Segmentation models, if the Output classes is not set to Tumor, the multiclass model will require multiple MRI scans as input (T1-w, T1-CE, T2, and FLAIR) for running successfully over the glioblastoma/low-grade glioma tumor types.

Those are ideas/suggestions that come to mind, let me know if you manage to solve your issue!

— Reply to this email directly, view it on GitHubhttps://github.com/raidionics/Raidionics/issues/39#issuecomment-1931850942, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A7SYDSCNNX2NTJ3QDF7TSQ3YSNQ33AVCNFSM6AAAAAAXUY4ASSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZRHA2TAOJUGI. You are receiving this because you were mentioned.Message ID: @.***>

dbouget commented 6 months ago

Great! I will close this issue for now, but will further investigate as to why the automatic download of models can sometimes fail.

I have also opened two other issues for the problems you mentioned (#69 and #70), so it will be easier to follow-up and get notified when a new release fixing the problems is available.