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

Resdnn inference #2520

Merged
merged 27 commits into from Mar 9, 2022
Merged

Resdnn inference #2520

merged 27 commits into from Mar 9, 2022

Conversation

frheault
Copy link
Contributor

@frheault frheault commented Feb 17, 2022

This PR is replacing #2123 and contains only the inference, no training.

It contains a model for [1] to predict fODF from raw DWI signal (as SH). It is not a local model like CSD or DTI, but the class has a fit function to make it easy to use on whole volumes.

This PR contains a fetcher for the weights, the predict/fit functions in the class, an example and simple tests.

[1] Nath, V., Schilling, K. G., Parvathaneni, P., Hansen, C. B., Hainline, A. E., Huo, Y., ... & Stepniewska, I. (2019). Deep learning reveals untapped information for local white-matter fiber reconstruction in diffusion-weighted MRI. Magnetic resonance imaging, 62, 220-227.

PS: I tried to run pytest, but I had difficulties. How can I efficiently check if the docstring and tests are right and up to the standard?

@skoudoro
Copy link
Member

Wow, Thank you for doing this! I started this morning to reshape, rebase, etc #2123. Should I continue? Otherwise, I can do a PR on your PR for some changes.

Concerning this PR, you need to put Tensorflow as an optional dependency and add some tests.

@skoudoro
Copy link
Member

I tried to run pytest, but I had difficulties. How can I efficiently check if the docstring and tests are right and up to the standard?

Can you tell us more ?

@pep8speaks
Copy link

pep8speaks commented Feb 17, 2022

Hello @frheault, Thank you for updating !

Line 55:81: E501 line too long (95 > 80 characters)
Line 56:81: E501 line too long (91 > 80 characters)

Comment last updated at 2022-03-08 22:02:25 UTC

@frheault
Copy link
Contributor Author

@skoudoro I think this PR should be the main one, I removed the training and changed the organization of the files.

As for the test, I can't seem to run pytest on my computer.
I can run python dipy/nn/test/test_histo_resdnn.py but pytest dipy/nn/test/test_histo_resdnn.py crashes immediately and I get a numpy error about compatibility... (Weird since I can easily run the test code manually)
image

@arokem
Copy link
Contributor

arokem commented Feb 17, 2022

@frheault : this is often the sign of a borked numpy installation. What version of numpy are you running there? What happens if you upgrade numpy in that env?

@skoudoro
Copy link
Member

Also, have you seen my PR in your branch ? frheault#1

Just doing some small correction

Otherwise, I agree with @arokem, Can you share your file to see if we reproduce the same issue.

@frheault
Copy link
Contributor Author

frheault commented Feb 18, 2022

@skoudoro the test file is now in the PR
@arokem new virtual environment with virtualenvwrapper: python3.7, pip install -e
pip_list.txt
. (for dipy) then pip install tensorflow.

(dipy 1.21, tensorflow 2.8, the rest is attached)

The test are running fine without pytest, is there a procedure I need to execute to run pytest myself? (Or a configuration file I need to edit?)

(I tried reinstalling numpy --with-binary and did not change a thing)

@skoudoro
Copy link
Member

I do not succeed to generate your issue. When I do pytest -svv dipy/nn/tests/test_histo_resdnn.py, all tests succeed, no crash.

Capture d’écran 2022-02-18 à 17 14 07

Also, do not forget to look and merge at some of my corrections in your PR frheault#1

@frheault
Copy link
Contributor Author

@skoudoro I will merge your PR, but keep the nibabel load/save.
I personally dislike quite a lot the load_nifti and save_nifti functions.
Thank you for all others fixes!

@skoudoro
Copy link
Member

I personally dislike quite a lot the load_nifti and save_nifti functions.

Interesting feedback, you are not the first one, can you tell me why? What is the biggest pain or misleading information with these 2 functions?

Resdnn Inference: Fix importing and update code
@skoudoro
Copy link
Member

I personally dislike quite a lot the load_nifti and save_nifti functions.

Also, the goal is to keep all tutorials consistent, using the same functionality for now.

@arokem
Copy link
Contributor

arokem commented Feb 18, 2022

In your list, I see

numpy                        1.21.5

From a search around the net, it seems that the issue you're seeing usually arises with tensorflow and numpy<1.16. I wonder if there is an issue with versions higher than some number as well...

@skoudoro : what version of numpy are you working with?

@skoudoro
Copy link
Member

@skoudoro : what version of numpy are you working with?

just created a new env. So tensorflow==2.8.0, numpy==1.22.2

@codecov
Copy link

codecov bot commented Feb 24, 2022

Codecov Report

Merging #2520 (c0b283d) into master (c312c15) will increase coverage by 0.20%.
The diff coverage is 85.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2520      +/-   ##
==========================================
+ Coverage   84.89%   85.09%   +0.20%     
==========================================
  Files         128      129       +1     
  Lines       17482    17578      +96     
  Branches     2982     2994      +12     
==========================================
+ Hits        14841    14958     +117     
+ Misses       1962     1924      -38     
- Partials      679      696      +17     
Impacted Files Coverage Δ
dipy/data/__init__.py 80.41% <ø> (ø)
dipy/data/fetcher.py 43.20% <80.00%> (+0.58%) ⬆️
dipy/nn/histo_resdnn.py 85.55% <85.55%> (ø)
dipy/io/stateful_tractogram.py 73.97% <100.00%> (+0.07%) ⬆️
dipy/nn/model.py 90.74% <0.00%> (+62.96%) ⬆️

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Hi @frheault,

Thank for the update. See below for some comments.

FYI, you did not need to remove the doctest/docstring, you just needed to add +skip not have_tf. Look at the example here

dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
Comment on lines +233 to +239
tmp_sf = sh_to_sf(sh=tmp_sh, sphere=sphere,
basis_type=self.basis_type,
sh_order=self.sh_order)
tmp_sf[tmp_sf < 0] = 0
tmp_sh = sf_to_sh(tmp_sf, sphere, smooth=0.0006,
basis_type=self.basis_type,
sh_order=self.sh_order)
Copy link
Member

Choose a reason for hiding this comment

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

this is strange to me. Why do you need to convert it and then come back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The model does predict negative fodf value (as SF), simply because this was not a constrained included in the original training/model.

But from SH you cannot remove negative value on SF, so you need to evaluate the SH, threshold, then fit new SH again.

Sub-optimal, yes. But necessary (I think)

doc/examples/histology_resdnn.py Outdated Show resolved Hide resolved
doc/examples/histology_resdnn.py Outdated Show resolved Hide resolved
doc/examples/histology_resdnn.py Outdated Show resolved Hide resolved
Copy link
Contributor

@arokem arokem left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this. Can't wait to try this out.

I had a few comments and suggestions

dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Show resolved Hide resolved
dipy/nn/histo_resdnn.py Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
@frheault
Copy link
Contributor Author

frheault commented Mar 3, 2022

@skoudoro I added the @doctest_skip_parser at the top of the init function and everything is crashing still because of the >>> in the doctest (that needs tensorflow). Did I do it wrong? (last commit added that)

dipy/nn/histo_resdnn.py Outdated Show resolved Hide resolved
@skoudoro
Copy link
Member

skoudoro commented Mar 4, 2022

Hi @frheault,

Thank you for the update.

Can you add Tensorflow to the coverage matrix of our CI's? You just need to add TensorFlow here

@skoudoro
Copy link
Member

skoudoro commented Mar 4, 2022

Is there any additional comment for this PR?

Copy link
Contributor

@Garyfallidis Garyfallidis left a comment

Choose a reason for hiding this comment

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

Thank you @frheault this is super close to be merged. Please correct the small requested changes. @skoudoro will make a quick PR on top of yours to help with memory reduction for visualization purposes.

doc/examples/histology_resdnn.py Outdated Show resolved Hide resolved
doc/examples/histology_resdnn.py Outdated Show resolved Hide resolved
doc/examples/histology_resdnn.py Outdated Show resolved Hide resolved
doc/examples/histology_resdnn.py Outdated Show resolved Hide resolved
@skoudoro
Copy link
Member

skoudoro commented Mar 8, 2022

Here is the PR frheault#2 @frheault, Feel free to merge it.

@skoudoro
Copy link
Member

skoudoro commented Mar 9, 2022

Thank you @frheault for this work. All concerns have been addressed so I am going ahead a merge this PR.

@skoudoro skoudoro merged commit c0c1fe9 into dipy:master Mar 9, 2022
@skoudoro skoudoro mentioned this pull request Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants