Error when running sct_extract_metric -vert

Dear Sir
Hello!
Recently I downloaded the latest version 5.0.1. I registered the dmri.nii to t2.nii following instructions.
However, value of each slice can be accquired successfully. but I failed to extract FA value from C1 to C4 perlevel. I typed “sct_extract_metric -i dti_FA.nii.gz -vert 1:4 -perlevel 1 -method map -l 34,35 -o fa_in_VH.csv” .

Load metric image...
Estimation for label: GM left dorsal horn
Traceback (most recent call last):
  File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_extract_metric.py", line 394, in <module>
    main(sys.argv[1:])
  File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_extract_metric.py", line 385, in main
    label_struc=label_struc, id_label=id_label, indiv_labels_ids=indiv_labels_ids)
  File "/home/felixi/sct/spinalcordtoolbox/aggregate_slicewise.py", line 428, in extract_metric
    map_clusters=map_clusters)
  File "/home/felixi/sct/spinalcordtoolbox/aggregate_slicewise.py", line 250, in aggregate_per_slice_or_level
    im_vert_level = Image(vert_level).change_orientation('RPI')
  File "/home/felixi/sct/spinalcordtoolbox/image.py", line 250, in __init__
    self.copy(param)
  File "/home/felixi/sct/spinalcordtoolbox/image.py", line 321, in copy
    self.im_file = deepcopy(image.im_file)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/copy.py", line 169, in deepcopy
    rv = reductor(4)
  File "indexed_gzip/indexed_gzip.pyx", line 956, in indexed_gzip.indexed_gzip.IndexedGzipFile.__reduce__
  File "indexed_gzip/indexed_gzip.pyx", line 737, in indexed_gzip.indexed_gzip._IndexedGzipFile.export_index
AttributeError: '_io.BytesIO' object has no attribute 'mode'

Hope for your reply!
Thanks!

Hi @felixi

I’m not sure what could be the cause of this error, I would need to try reproducing the error myself. Could you please share the two files I need to run your command (zip everything and upload here):

  • dti_FA.nii.gz
  • label/template/PAM50_levels.nii.gz

Hi Jcohenadad
Thanks for your reply!
Here is my files.
PAM50_levels.nii.gz (810 Bytes) dti_FA.nii.gz (96.1 KB)

Could you actually zip the entire label/ folder and upload it?

Hi Jcohenadad,
I was wondering where can I download the former version. Because I did not have this problems in former version.
Thanks!
label.zip (690.0 KB)

I was wondering where can I download the former version. Because I did not have this problems in former version.

I strongly advise against it. More recent versions include improvements and bug fixes. We just need to figure out what is going on with your installation.

I am not able to reproduce your error:

julien-macbook:~/Desktop $ sct_extract_metric -i dti_FA.nii.gz -vert 1:4 -perlevel 1 -method map -l 34,35 -o fa_in_VH.csv

--
Spinal Cord Toolbox (git-al/deepseg_custom_task-e362d026408ff92600fa726653772356ecf8b445)

sct_extract_metric -i dti_FA.nii.gz -vert 1:4 -perlevel 1 -method map -l 34,35 -o fa_in_VH.csv
--


Load metric image...
Estimation for label: GM left dorsal horn
Estimation for label: GM right dorsal horn

Done! To view results, type:
open fa_in_VH.csv

Could you please run the following command:

sct_check_dependencies
sct_testing

Then copy/paste the output terminal in a file and upload the file here.

Thanks

sct_check_dependencies

--
Spinal Cord Toolbox (git-master-3dfd4f81f9e4364dab4d94894ea687a625dbdea5)

sct_check_dependencies
--

SCT info:
- version: git-master-3dfd4f81f9e4364dab4d94894ea687a625dbdea5
- path: /home/felixi/sct
OS: linux (Linux-4.4.0-18362-Microsoft-x86_64-with-debian-bullseye-sid)
CPU cores: Available: 12, Used by ITK functions: 12
RAM: Total: 8068MB, Used: 3624MB, Available: 4403MB
Check Python executable.............................[OK]
  Using bundled python 3.6.12 |Anaconda, Inc.| (default, Sep  8 2020, 23:10:56)
[GCC 7.3.0] at /home/felixi/sct/python/envs/venv_sct/bin/python
Check if data are installed.........................[OK]
Check if colored is installed.......................[OK] (1.4.2)
Check if dipy is installed..........................[OK] (1.3.0)
Check if futures is installed.......................[OK]
Check if h5py is installed..........................
[OK] (3.1.0)
Check if Keras (2.1.5) is installed.................[OK] (2.1.5)
Check if ivadomed (2.6.1) is installed..............
Bad key "text.kerning_factor" on line 4 in
/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test_patch.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution
[OK] (2.6.1)
Check if matplotlib is installed....................[OK] (3.1.1)
Check if nibabel is installed.......................[OK] (3.2.1)
Check if numpy is installed.........................[OK] (1.19.4)
Check if onnxruntime (1.4.0) is installed...........[OK] (1.4.0)
Check if pandas is installed........................[OK] (1.1.5)
Check if psutil is installed........................[OK] (5.8.0)
Check if pyqt5 (5.11.3) is installed................[OK] (5.11.3)
Check if pytest is installed........................[OK] (6.2.1)
Check if pytest-cov is installed....................[OK] (__version__ = '2.10.1')
Check if raven is installed.........................[OK]
Check if requests is installed......................[OK] (2.13.0)
Check if requirements-parser is installed...........[OK] (0.2.0)
Check if scipy is installed.........................[OK] (1.5.3)
Check if scikit-image is installed..................[OK] (0.17.2)
Check if scikit-learn is installed..................[OK] (0.24.0)
Check if tensorflow (1.5.0) is installed............[OK] (1.5.0)
Check if torch (1.5.0+cpu) is installed.............[OK] (1.5.0+cpu)
Check if torchvision (0.6.0+cpu) is installed.......[OK] (0.6.0+cpu)
Check if xlwt is installed..........................[OK] (1.3.0)
Check if tqdm is installed..........................[OK] (4.56.0)
Check if transforms3d is installed..................[OK] (0.3.1)
Check if urllib3 is installed.......................[OK] (1.26.2)
Check if pytest_console_scripts is installed........[OK]
Check if pytest-xdist is installed..................[OK] (2.2.0)
Check if tensorboard (1.14.0) is installed..........[WARNING] (2.4.0 != 1.14.0 mandated version))
Check if spinalcordtoolbox is installed.............[OK]
Check ANTs compatibility with OS ...................[OK]
Check PropSeg compatibility with OS ................[OK]
Check if DISPLAY variable is set....................[OK]
Check if figure can be opened with PyQt.............failed to get the current screen resources
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-felixi'
[OK]

sct_testing

--
Spinal Cord Toolbox (git-master-3dfd4f81f9e4364dab4d94894ea687a625dbdea5)

sct_testing
--

Creating temporary folder (/tmp/sct-20210113094418.980911-bgm0mv2e)
Will run through the following tests:
- sequentially: sct_deepseg_gm sct_deepseg_lesion sct_deepseg_sc
- in parallel with 12 jobs: sct_analyze_lesion sct_analyze_texture sct_apply_transfo sct_convert sct_compute_ernst_angle sct_compute_hausdorff_distance sct_compute_mtr sct_compute_mscc sct_compute_snr sct_create_mask sct_crop_image sct_dice_coefficient sct_detect_pmj sct_dmri_compute_dti sct_dmri_concat_b0_and_dwi sct_dmri_concat_bvals sct_dmri_concat_bvecs sct_dmri_compute_bvalue sct_dmri_moco sct_dmri_separate_b0_and_dwi sct_dmri_transpose_bvecs sct_extract_metric sct_flatten_sagittal sct_fmri_compute_tsnr sct_fmri_moco sct_get_centerline sct_image sct_label_utils sct_label_vertebrae sct_maths sct_merge_images sct_process_segmentation sct_propseg sct_qc sct_register_multimodal sct_register_to_template sct_resample sct_smooth_spinalcord sct_straighten_spinalcord sct_warp_template
Checking sct_deepseg_gm.............................[FAIL]

   ====================================================================================================
   sct_deepseg_gm -i t2s/t2s_uncropped.nii.gz -o output.nii.gz -qc testing-qc
   ====================================================================================================


   --
   Spinal Cord Toolbox (git-master-3dfd4f81f9e4364dab4d94894ea687a625dbdea5)

   sct_deepseg_gm -i t2s/t2s_uncropped.nii.gz -o output.nii.gz -qc testing-qc
   --

   Traceback (most recent call last):
   File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_deepseg_gm.py", line 138, in <module>
   main(sys.argv[1:])
   File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_deepseg_gm.py", line 121, in main
   use_tta)
   File "/home/felixi/sct/spinalcordtoolbox/deepseg_gm/deepseg_gm.py", line 313, in segment_file
   use_tta)
   File "/home/felixi/sct/spinalcordtoolbox/deepseg_gm/deepseg_gm.py", line 233, in segment_volume
   deepgmseg_model.load_weights(model_abs_path)
   File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/keras/engine/topology.py", line 2656, in load_weights
   f, self.layers, reshape=reshape)
   File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/keras/engine/topology.py", line 3328, in load_weights_from_hdf5_group
   original_keras_version = f.attrs['keras_version'].decode('utf8')
   AttributeError: 'str' object has no attribute 'decode'
Checking sct_deepseg_lesion.........................[FAIL]

   ====================================================================================================
   sct_deepseg_lesion -i t2/t2.nii.gz -c t2
   ====================================================================================================


   --
   Spinal Cord Toolbox (git-master-3dfd4f81f9e4364dab4d94894ea687a625dbdea5)

   sct_deepseg_lesion -i t2/t2.nii.gz -c t2
   --


   Method:
   Centerline algorithm: svm
   Assumes brain section included in the image: True

   Creating temporary folder (/tmp/sct-20210113094425.407736-hkl1okl7)
   Reorient the image to RPI, if necessary...

   Finding the spinal cord centerline...
   Creating temporary folder (/tmp/sct-20210113094425.641797-9ivjqszk)
   Remove temporary files...
   rm -rf /tmp/sct-20210113094425.641797-9ivjqszk

   Cropping the image around the spinal cord...
   Normalizing the intensity...
   load data...

   Segmenting the MS lesions using deep learning on 3D patches...
   Traceback (most recent call last):
   File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_deepseg_lesion.py", line 173, in <module>
   main(sys.argv[1:])
   File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_deepseg_lesion.py", line 149, in main
   brain_bool=brain_bool, remove_temp_files=remove_temp_files, verbose=verbose)
   File "/home/felixi/sct/spinalcordtoolbox/deepseg_lesion/core.py", line 201, in deep_segmentation_MSlesion
   im=im_res3d.copy())
   File "/home/felixi/sct/spinalcordtoolbox/deepseg_lesion/core.py", line 88, in segment_3d
   seg_model = load_trained_model(model_fname)
   File "/home/felixi/sct/spinalcordtoolbox/deepseg_sc/cnn_models_3d.py", line 91, in load_trained_model
   return load_model(model_file, custom_objects=custom_objects)
   File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/keras/models.py", line 242, in load_model
   model_config = json.loads(model_config.decode('utf-8'))
   AttributeError: 'str' object has no attribute 'decode'
Checking sct_deepseg_sc.............................[FAIL]

   ====================================================================================================
   sct_deepseg_sc -i t2/t2.nii.gz -c t2 -qc testing-qc
   ====================================================================================================


   --
   Spinal Cord Toolbox (git-master-3dfd4f81f9e4364dab4d94894ea687a625dbdea5)

   sct_deepseg_sc -i t2/t2.nii.gz -c t2 -qc testing-qc
   --

   Config deepseg_sc:
   Centerline algorithm: svm
   Brain in image: True
   Kernel dimension: 2d
   Contrast: t2
   Threshold: 0.7
   Creating temporary folder (/tmp/sct-20210113094429.549378-2taz61qy)
   Reorient the image to RPI, if necessary...
   Finding the spinal cord centerline...
   Creating temporary folder (/tmp/sct-20210113094429.786930-2qvfuikl)
   Remove temporary files...
   rm -rf /tmp/sct-20210113094429.786930-2qvfuikl
   Cropping the image around the spinal cord...
   Normalizing the intensity...
   Segmenting the spinal cord using deep learning on 2D patches...
   Traceback (most recent call last):
   File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_deepseg_sc.py", line 204, in <module>
   main(sys.argv[1:])
   File "/home/felixi/sct/spinalcordtoolbox/scripts/sct_deepseg_sc.py", line 188, in main
   threshold_seg=threshold, remove_temp_files=remove_temp_files, verbose=verbose)
   File "/home/felixi/sct/spinalcordtoolbox/deepseg_sc/core.py", line 506, in deep_segmentation_spinalcord
   im_in=im_norm_in)
   File "/home/felixi/sct/spinalcordtoolbox/deepseg_sc/core.py", line 347, in segment_2d
   seg_model.load_weights(model_fname)
   File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/keras/engine/topology.py", line 2656, in load_weights
   f, self.layers, reshape=reshape)
   File "/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/keras/engine/topology.py", line 3328, in load_weights_from_hdf5_group
   original_keras_version = f.attrs['keras_version'].decode('utf8')
   AttributeError: 'str' object has no attribute 'decode'
Checking sct_analyze_lesion.........................[OK]
Checking sct_analyze_texture........................
Bad key "text.kerning_factor" on line 4 in
/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test_patch.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution

Bad key "text.kerning_factor" on line 4 in
/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test_patch.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution

Bad key "text.kerning_factor" on line 4 in
/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test_patch.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution
Bad key "text.kerning_factor" on line 4 in
/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test_patch.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution
Bad key "text.kerning_factor" on line 4 in
/home/felixi/sct/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test_patch.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution[OK]



Checking sct_apply_transfo..........................



[OK]
Checking sct_convert................................[OK]
Checking sct_compute_ernst_angle....................[OK]
Checking sct_compute_hausdorff_distance.............[OK]
Checking sct_compute_mtr............................[OK]
Checking sct_compute_mscc...........................[OK]
Checking sct_compute_snr............................[OK]
Checking sct_create_mask............................[OK]
Checking sct_crop_image.............................[OK]
Checking sct_dice_coefficient.......................[OK]
Checking sct_detect_pmj.............................[OK]
Checking sct_dmri_compute_dti.......................[OK]
Checking sct_dmri_concat_b0_and_dwi.................[OK]
Checking sct_dmri_concat_bvals......................[OK]
Checking sct_dmri_concat_bvecs......................[OK]
Checking sct_dmri_compute_bvalue....................[OK]
Checking sct_dmri_moco..............................[OK]
Checking sct_dmri_separate_b0_and_dwi...............[OK]
Checking sct_dmri_transpose_bvecs...................[OK]
Checking sct_extract_metric.........................[OK]
Checking sct_flatten_sagittal.......................[OK]
Checking sct_fmri_compute_tsnr......................[OK]
Checking sct_fmri_moco..............................[OK]
Checking sct_get_centerline.........................[OK]
Checking sct_image..................................[OK]
Checking sct_label_utils............................[OK]
Checking sct_label_vertebrae........................[OK]
Checking sct_maths..................................[OK]
Checking sct_merge_images...........................[OK]
Checking sct_process_segmentation...................[OK]
Checking sct_propseg................................[OK]
Checking sct_qc.....................................[OK]
Checking sct_register_multimodal....................[OK]
Checking sct_register_to_template...................



[OK]
Checking sct_resample...............................[OK]
Checking sct_smooth_spinalcord......................[OK]
Checking sct_straighten_spinalcord..................[OK]
Checking sct_warp_template..........................[OK]
status: [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Failures: sct_deepseg_gm sct_deepseg_lesion sct_deepseg_sc
Finished! Elapsed time: 138s

Thank you. First of all, it seems like you are not running v5.0.1, but the git installation (commit 3dfd4f81f9e4364dab4d94894ea687a625dbdea5).

The problem you experienced has already been reported by a user: AttributeError: 'str' object has no attribute 'decode' - v5.0.0.

@joshuacwnewton will follow-up with you on this.

Thank you for reporting this issue,
Julien

1 Like

Hi @felixi. Could you please follow the instructions from the Install from package section of our documentation? You will need to download and unzip the Source Code (.zip) file, then run the install script from there. :slightly_smiling_face:

Thank you kindly,
Joshua

1 Like

Hi Joshua
After reinstalling,the problem solved.
I really appreciate your help!
THANK YOU!

2 Likes

Glad to hear! Feel free to keep using this forum in the future if you have any other questions. :smile:

Kind regards,
Joshua