Hi,
I have this error when running sct_deepseg spinalcord (sct 7.2) - Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-163-generic x86_64)
--
Spinal Cord Toolbox (7.2)
sct_deepseg spinalcord -i /cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_data/derivatives/processing/preprocessing/sub-094/anat/sub-094_T2star.nii.gz -c t2 -thr 0.01 -o /cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_data/derivatives/processing/preprocessing/sub-094/anat/sct_deepseg/sub-094_T2star_seg.nii.gz -qc /cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_data/derivatives/processing/preprocessing/QC/ -qc-subject sub-094 -v 0
--
Traceback (most recent call last):
File "/cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_analysis/toolboxes/sct_7.2/spinalcordtoolbox/scripts/sct_deepseg.py", line 623, in <module>
main(sys.argv[1:])
File "/cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_analysis/toolboxes/sct_7.2/spinalcordtoolbox/scripts/sct_deepseg.py", line 489, in main
im_lst, target_lst = inference.segment_non_ivadomed(
File "/cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_analysis/toolboxes/sct_7.2/spinalcordtoolbox/deepseg/inference.py", line 131, in segment_non_ivadomed
net = create_net(path_model, device, **extra_network_kwargs)
TypeError: segment_non_ivadomed.<locals>.create_net() got an unexpected keyword argument 'test_time_aug'
I have also updated to Spinal Cord Toolbox (7.3.dev0) and had the same issue
However, I was not able to reproduce the error on macOS 14.1 & sct 7.2
Do you have any idea where the error is coming from? Could it be related to any dependency that it is not install in my environnement ?
Cheers,
Caroline
Hi @Caroline_Landelle,
Thanks so much for your question! We would be happy to help debug.
sct_deepseg spinalcord -i /cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_data/derivatives/processing/preprocessing/sub-094/anat/sub-094_T2star.nii.gz
-c t2
-thr 0.01
-o /cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_data/derivatives/processing/preprocessing/sub-094/anat/sct_deepseg/sub-094_T2star_seg.nii.gz
-qc /cerebro/cerebro1/dataset/spine_7t/spine_7t_fmri_data/derivatives/processing/preprocessing/QC/
-qc-subject sub-094
-v 0
The good news is that I don’t see anything wrong with the command you used!
Here are some technical notes (just for posterity) to try and explain the cause of the error:
- SCT v7.2 has a
-test-time-aug argument set to “action=store_true” that appears for any non-spine tasks. By default, the value is set to False.
- The
-test-time-aug argument gets parsed as arguments.test_time_aug, and then set to extra_network_kwargs = { 'test_time_aug': False } here: spinalcordtoolbox/spinalcordtoolbox/scripts/sct_deepseg.py at 411958dc8a54a854271e603a6871d35683ed5002 · spinalcordtoolbox/spinalcordtoolbox · GitHub
- These extra network keyword arguments get passed to the
create_net function corresponding to whichever model framework is used (MONAI, nnunetv2, etc.) here: spinalcordtoolbox/spinalcordtoolbox/deepseg/inference.py at 4f5dba4122e225e95c096c0a79fa9edfc16ce646 · spinalcordtoolbox/spinalcordtoolbox · GitHub
- nnunetv2 has support for
-test-time-aug, but MONAI does not (!!)
- SCT no longer has any MONAI models because we transitioned
spinalcord from MONAI to nnunetv2, but SCT still retained the old MONAI framework just in case we ever develop a new MONAI model.
- However, if a user still has the old MONAI models (or is using a custom model URL), then
sct_deepseg will try to pass this nnunetv2-specific argument to the MONAI network function, and the function will crash. (In other words, we need to add logic to the MONAI functions to ignore the nnunetv2-specific -test-time-aug argument.)
Some questions to confirm my suspicions:
- Do you have an older version of the
spinalcord model installed?
- Have you used the
-custom-url argument when installing the spinalcord model?
If either of these are true, then updating to the newest version of the spinalcord model using sct_deepseg spinalcord -install should fix the issue.
If you still need the older version of spinalcord model, please let me know and I can figure out an alternate solution for you. 
Kind regards,
Joshua
1 Like
Thank you Joshua,
Yes I probably have older spinal cord model installed as I am working on different projects using different sct version. However for each project I set up the path toward the right sct version like SCT_DIR=$PATH_CODE/toolboxes/sct_7.2
I don’t think I have used -custom-url argument.
Unfortunatly sct_deepseg spinalcord -install did not fixed the issue
Thank you for your help !
Thank you so much for trying this step. On further reflection, I see that my initial investigation was wrong, and you don’t have an old model version.
The real problem is actually due to a bug in SCT’s code. We will fix this shortly. For now, you can run the following command to update your SCT installation and remove this bug:
# fix the buggy line in SCT's code
sed -i 's/if "spine" in path_model:/if os.path.basename(path_model) == "spine":/' "$SCT_DIR/spinalcordtoolbox/deepseg/inference.py"
Please let me know if this fixes the issue for you and then I will go ahead and apply this change to SCT’s codebase. Thank you for your patience and understanding.
Kindly,
Joshua
Excellent !
Thank you Joshua, the command fixed the bug on my side
Best,
Caroline