Hi,
I’m trying to segment lesion on spinal cord from MP2RAGE images, the task seg_ms_lesion_mp2rage seems perfect for that but for most of my subjects it finds lesions outside of the spinal cord even though there are very visible lesion on the spinal cord. Can you help me figure out why lesion segmentation doesn’t work on my data ?
Here is a close up into what I’m doing :
The image I use is MP2RAGE UNI (spacing : [1, 0.903409, 0.903409] and size : [176, 300, 352]) as this issue showed it works best compare to MP2RAGE T1q.
Segmentation of spinal cord to obtain sc_seg.nii.gz is done with sct_deepseg -i MP2RAGE_UNI.nii.gz -o sc_seg.nii.gz -task seg_ms_sc_mp2rage, the output is manually corrected if necessary. I then crop the image into *MP2RAGE_crop.nii.gz* with the sct_crop_image -i MP2RAGE_UNI.nii.gz -m sc_seg.nii.gz -dilate 32x0x32command as recommended insct_deepseg -list-tasks. And then sct_deepseg -i MP2RAGE_crop.nii.gz -o lesionseg.nii.gz -task seg_ms_lesion_mp2rage`.
Here are my dependancies :
--
Spinal Cord Toolbox (6.2)
sct_check_dependencies
--
SYSTEM INFORMATION
------------------
SCT info:
- version: 6.2
- path: /home/nolwenn/sct_6.2
OS: linux (Linux-6.8.0-40-generic-x86_64-with-glibc2.35)
CPU cores: Available: 12, Used by ITK functions: 12
RAM: Total: 15627MB, Used: 4395MB, Available: 9218MB
OPTIONAL DEPENDENCIES
---------------------
Check FSLeyes version...............................[OK] (1.10.4)
MANDATORY DEPENDENCIES
----------------------
Check Python executable.............................[OK]
Using bundled python 3.9.18 (main, Sep 11 2023, 13:41:44)
[GCC 11.2.0] at /home/nolwenn/sct_6.2/python/envs/venv_sct/bin/python
Check if data are installed.........................[OK]
Check if dipy is installed..........................[OK] (1.5.0)
Check if ivadomed is installed......................[OK] (2.9.9)
Check if matplotlib is installed....................[OK] (3.8.3)
Check if monai is installed.........................[OK] (1.3.0)
Check if nibabel is installed.......................[OK] (3.2.2)
Check if nilearn is installed.......................[OK] (0.10.2)
Check if nnunetv2 is installed......................[OK]
Check if numpy is installed.........................[OK] (1.23.5)
Check if onnxruntime is installed...................[OK] (1.17.0)
Check if pandas is installed........................[OK] (1.4.4)
Check if portalocker is installed...................[OK] (2.8.2)
Check if psutil is installed........................[OK] (5.9.8)
Check if pyqt5 (5.12.3) is installed................[OK] (5.12.3)
Check if pyqt5-sip is installed.....................[OK]
Check if pytest is installed........................[OK] (8.0.0)
Check if pytest-cov is installed....................[OK] (4.1.0)
Check if requests is installed......................[OK] (2.31.0)
Check if requirements-parser is installed...........[OK]
Check if scipy is installed.........................[OK] (1.12.0)
Check if scikit-image is installed..................[OK] (0.22.0)
Check if scikit-learn is installed..................[OK] (1.4.0)
Check if xlwt is installed..........................[OK] (1.3.0)
Check if tqdm is installed..........................[OK] (4.66.2)
Check if transforms3d is installed..................[OK] (0.4.1)
Check if urllib3 is installed.......................[OK] (2.2.0)
Check if pytest_console_scripts is installed........[OK]
Check if pyyaml is installed........................[OK] (6.0.1)
Check if voxelmorph is installed....................[OK] (0.2)
Check if wquantiles is installed....................[OK] (0.4)
Check if xlsxwriter is installed....................[OK] (3.1.9)
Check if spinalcordtoolbox is installed.............[OK]
Check ANTs compatibility with OS ...................[OK]
Check PropSeg compatibility with OS ................[OK]
Check if figure can be opened with PyQt.............Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[OK]
Check if figure can be opened with matplotlib.......[OK] (Using GUI backend: 'QtAgg')
The model you are using to segment the cord is sub-optimal. For example, in one of the image you shared, the segmentation stops below an MS lesion. I recommend you use the contrast-agnostic model, which has been updated as of SCT v6.4. See example below (red: seg_ms_sc_mp2rage | green: seg_sc_contrast_agnostic):
Problem with cropping
Your images have RAS orientation, therefore the dilate command you used is wrong. It should be 32x32x0 instead of 32x0x32.
Hi,
I have a new issue, the sct_deepseg with the contrast agnostic task used to work on MP2RAGE UNI data but doesn’t anymore even though my setup hasn’t changed a lot. I’m working with SCT6.4 on ubuntu and there is no error, the file is just not created :
Spinal Cord Toolbox (6.4)
sct_deepseg -i /home/MP2RAGE-UNI_DIS.nii.gz -o /home/MP2RAGE-UNI_sc_seg.nii.gz -task seg_sc_contrast_agnostic -c t1
--
Model 'model_seg_sc_contrast_agnostic_softseg_monai' is up to date (Source: https://github.com/sct-pipeline/contrast-agnostic-softseg-spinalcord/releases/download/v2.4/model_soft_bin_20240425-170840.zip)
/home/nolwenn/sct_6.4/spinalcordtoolbox/deepseg/monai.py:119: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
checkpoint = torch.load(chkp_path, map_location=torch.device(device))["state_dict"]
Creating temporary folder (/tmp/sct_2025-04-07_17-45-39_sct_deepseg_wr2q03yh)
Copied /home/MP2RAGE-UNI.nii.gz to /tmp/sct_2025-04-07_17-45-39_sct_deepseg_wr2q03yh/MP2RAGE-UNI_DIS.nii.gz
Starting inference...
The process stops there and the file is never created.
Thanks a lot for your help,
Nolwenn
Thank you for reporting this issue, and our apologies for any inconvenience.
This is very strange! We have testing infrastructure to make sure that past releases still work as they should. For example: SCT v6.4, Ubuntu passed just yesterday. Also, the “contrast agnostic” model release has not changed since May 2024.
I see earlier in the issue that SCT v6.2 had been working for you. So, I have the following questions:
Did the issue occur when switching from SCT v6.2 to SCT v6.4?
Or, was SCT v6.4 working at one point, and then suddenly stopped working?
Also, could you please share the output of the following command:
grep -i spinalcordtoolbox ~/.bashrc
This should return a list of dates at which SCT was installed. For example, in my case, I see:
Hi, well I tried the same command this morning and everything is running smoothly I don’t know what happened yesterday.
Thank you for your quick answer.
Here is the bit of code you requested.
# SPINALCORDTOOLBOX (installed on 2024-02-28 11:39:59)
# SPINALCORDTOOLBOX (installed on 2024-09-09 16:35:01)