Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ValueError and IndexError #2060

Merged

Conversation

charleygros
Copy link
Member

@charleygros charleygros commented Nov 8, 2018

This PR aimed at fixing some ValueError or IndexError errors that have been reported to occur when using sct_deepseg_sc or sct_deepseg_lesion.

#2016

To reproduce the error:

cd example_data/mt
sct_image -i mt1.nii.gz -split z
sct_deepseg_sc -i mt1_Z0005.nii.gz -c t2 -centerline cnn

Error:

charley@charley:~/data/example_data/mt$ sct_deepseg_sc -i mt1_Z0005.nii.gz -c t2 -centerline cnn

--
Spinal Cord Toolbox (cg_deepseg_valueError_indexError_i1921_i2015_i2016/9d9b320757fc4a1db5bac3f706a01817c6b351c7)
Running /home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py -i mt1_Z0005.nii.gz -c t2 -centerline cnn
/home/charley/spinalcordtoolbox/python/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

Method:
	Centerline algorithm: cnn
	Assumes brain section included in the image: True
	Dimension of the segmentation kernel convolutions: 2d

Creating temporary folder...
cp mt1_Z0005.nii.gz /tmp/sct-20181108144431.270174-WGI6gM
Reorient the image to RPI, if necessary...
Resample the image to 0.5 mm isotropic resolution...
/home/charley/spinalcordtoolbox/python/lib/python2.7/site-packages/nipy/io/files.py:145: FutureWarning: Default `strict` currently False; this will change to True in a future version of nipy
  ni_img = nipy2nifti(img, data_dtype = io_dtype)
Finding the spinal cord centerline...
WARNING: To avoid intensity overflow due to convertion to uint8, intensity will be rescaled to the maximum quantization scale.
Traceback (most recent call last):
  File "/home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py", line 853, in <module>
    main()
  File "/home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py", line 844, in main
    remove_temp_files=remove_temp_files, verbose=verbose)
  File "/home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py", line 677, in deep_segmentation_spinalcord
    centerline_fname=file_ctr)
  File "/home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py", line 478, in find_centerline
    brain_bool=brain_bool)
  File "/home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py", line 391, in heatmap
    z_max = np.max(list(set(np.where(data)[2])))
  File "/home/charley/spinalcordtoolbox/python/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2334, in amax
    initial=initial)
  File "/home/charley/spinalcordtoolbox/python/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 83, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation maximum which has no identity
Sentry is attempting to send 1 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit
Total processing time: 0 min 6 s

It should be noted that this error did not occur when using -centerline svm. Also, this is not related to the fact that the input image is a single axial slice, since recent improvements (see PR_2012) allow to handle this kind of input.
For instance, the below command works:

sct_deepseg_sc -i mt1_Z0005.nii.gz -c t2 -centerline cnn

Proposed solution:
The reported error occurs when the spinal cord was not detected (here on the single axial slice). There is no much that we can do about it. Consequently, I proposed in the PR to invite the user to use another -centerline method, such as svm or viewer:

charley@charley:~/data/example_data/mt$ sct_deepseg_sc -i mt1_Z0005.nii.gz -c t2 -centerline cnn

--
Spinal Cord Toolbox (cg_deepseg_valueError_indexError_i1921_i2015_i2016/9d9b320757fc4a1db5bac3f706a01817c6b351c7)
Running /home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py -i mt1_Z0005.nii.gz -c t2 -centerline cnn
/home/charley/spinalcordtoolbox/python/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

Method:
	Centerline algorithm: cnn
	Assumes brain section included in the image: True
	Dimension of the segmentation kernel convolutions: 2d

Creating temporary folder...
cp mt1_Z0005.nii.gz /tmp/sct-20181108163141.602759-T16TNs
Reorient the image to RPI, if necessary...
Resample the image to 0.5 mm isotropic resolution...
/home/charley/spinalcordtoolbox/python/lib/python2.7/site-packages/nipy/io/files.py:145: FutureWarning: Default `strict` currently False; this will change to True in a future version of nipy
  ni_img = nipy2nifti(img, data_dtype = io_dtype)
Finding the spinal cord centerline...
WARNING: To avoid intensity overflow due to convertion to uint8, intensity will be rescaled to the maximum quantization scale.

Spinal cord was not detected using "-centerline cnn". Please try another "-centerline" method.

Sentry is attempting to send 1 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit
Total processing time: 0 min 6 s

#2015 & #1921

To reproduce:

cd example_data/t2
sct_deepseg_sc -i t2.nii.gz -c t2 -kernel 3d

Error:
It raised an IndexError when an empty slice segmentation is encountered by the function post_processing_slice_wise.

Proposed solution:
Use the center of mass of the neighbour slices to perform the slice wise post processing. If the neighbours are also empty (ie all the slices of a 3D patches are not segmented), then no post-processing is performed.

--> Tested on the example_data and it fixes the present error without impacting the output segmentation.

#2001

This issue suggests to correct the Usage of sct_deepseg_lesion since -c t2_ax is not a type of contrast but a contrast_orientation.

Proposed solution:
Clarify the usage:

 -c {t2,t2_ax,t2s}            type of image contrast. For 't2_like' contrast images, a specific 
                              model for images with axial orientation is available: 't2_ax'.

#2057

svm is now the -centerline default value for all contrasts , as indicated in the Usage.

charley@charley:~/data/example_data/t1$ sct_deepseg_sc -i t1.nii.gz -c t1

--
Spinal Cord Toolbox (cg_deepseg_valueError_indexError_i1921_i2015_i2016/d2f524f877add0fa59cbfc0d78e27db69afc390b)
Running /home/charley/spinalcordtoolbox/scripts/sct_deepseg_sc.py -i t1.nii.gz -c t1
/home/charley/spinalcordtoolbox/python/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

Method:
	Centerline algorithm: svm
	Assumes brain section included in the image: True
	Dimension of the segmentation kernel convolutions: 2d

#1825

To reproduce:

cd example_data/t2s
sct_deepseg_sc -i t2s.nii.gz -c t2s -ofolder test_folder

Error:
Duplication of output_folder in the display_syntax_viewer:

fsleyes t2s.nii.gz -cm greyscale test_folder/test_folder/t2s_seg.nii.gz -cm red -a 70.0 &

This is now fixed:

fsleyes t2s.nii.gz -cm greyscale test_folder/t2s_seg.nii.gz -cm red -a 70.0 &

@charleygros charleygros added bug category: fixes an error in the code card:WORK_IN_PROCESS sct_deepseg_sc context: sct_deepseg_lesion context: labels Nov 8, 2018
@charleygros charleygros self-assigned this Nov 8, 2018
@charleygros
Copy link
Member Author

PR ready for review.

@jcohenadad jcohenadad added this to the v3.2.8 milestone Nov 12, 2018
@@ -47,7 +47,7 @@ def get_parser():
example="t1.nii.gz")
parser.add_option(name="-c",
type_value="multiple_choice",
description="type of image contrast.",
description="type of image contrast. For 't2_like' contrast images, a specific model for images with axial orientation is available: 't2_ax'.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more exhaustive in the description. E.g.: "type of image contrast. t2: T2w scan with isotropic resolution. t2_ax: T2w scan with axial orientation and thick slices. t2s: T2*w scan with axial orientation and thick slices."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback. It has been corrected.

Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice-- just a minor change in the description. Thanks for this fix!

… into cg_deepseg_valueError_indexError_i1921_i2015_i2016
@charleygros charleygros merged commit bbbf7b4 into master Nov 21, 2018
@charleygros charleygros deleted the cg_deepseg_valueError_indexError_i1921_i2015_i2016 branch November 21, 2018 05:48
@jcohenadad jcohenadad changed the title sct_deepseg_sc/lesion -- ValueError and IndexError fixes Fixed ValueError and IndexError Nov 22, 2018
jcohenadad pushed a commit that referenced this pull request Dec 18, 2019
…ror_i1921_i2015_i2016

sct_deepseg_sc/lesion -- ValueError and IndexError fixes

Former-commit-id: bbbf7b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category: fixes an error in the code sct_deepseg_lesion context: sct_deepseg_sc context:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants