-
Notifications
You must be signed in to change notification settings - Fork 132
Tomography operator with astra-toolbox #474
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
Conversation
deepinv/tests/test_physics.py
Outdated
| r = physics.A_adjoint(physics.A(x)) | ||
| y = physics.A(r) | ||
| error = torch.linalg.norm(physics.A_dagger(y) - r) / torch.linalg.norm(r) | ||
| assert error < 0.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a quite high threshold given that you (correctly) test on the range of A... Do you think it's possible to reduce this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although we test on the range of A, I guess because the adjoint is not matched we still get a somewhat high error.
I have fixed the detector and angular parameters of the fan/cone setup to set a nicer geometry with a proper field of view. At such low-resolution, the error does not seem to go below 0.05 for parallel, though it does decrease with higher resolution.. For fan/cone beam the error is a little higher (0.1/0.15), which is expected.
Andrewwango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and it's really cool to provide this functionality! Some intermediate minor comments:
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #474 +/- ##
==========================================
+ Coverage 79.85% 80.77% +0.91%
==========================================
Files 187 189 +2
Lines 16822 17226 +404
Branches 2213 2282 +69
==========================================
+ Hits 13434 13914 +480
+ Misses 2661 2532 -129
- Partials 727 780 +53 ☔ View full report in Codecov by Sentry. |
|
Hi everyone. I've tried to resolve the last checks failing. The doc won't build for some files because TomographyWithAstra only supports CUDA operations, this concerns:
Overall, I've implemented the tests and docs to be skipped if there is no GPU, I guess this is why the code coverage marks most of the implemented functions as not tested ? Another point concerns the supported platform, at the moment, ASTRA only provides a pip package for linux. To get support for windows, you need to install it via their conda channel. I've restricted the dependency install to Linux platform for the moment. |
…ics. Add pytest parameters to test_tomography_with_astra.
…e filename_pattern in sphinx_gallery_conf
…r setting geometry via a set of vectors
|
One solution to the lack of CPU tests that we discussed with @tachella is to mock the Astra library calls, like @jscanvic does to create dataset tests when we can't actually download the datasets in #490. Do you think this could be possible? The philosophy here is that as Astra is an external library, our tests should not have to cover its functionality, only our own wrapper. Then it is also ok that we don't have tests for adjointness etc, only that it runs ok and outputs correct shapes etc. Would you agree with this idea? |
It seems like a good alternative while there is no GPU for testing ! I'll dig into it and come up with a solution. Although, I think keeping the already written tests in the codebase might be a good idea, at least it gives the ability to check on local machines that next versions of ASTRA or torch don't change the intented behaviour, in particular for the pseudo-inverse which is half torch, half astra code. |
|
@Andrewwango I've patched the calls to the astra kernel with dummy functions in a new test, it should be good, tell me what you think. I put it in a |
Andrewwango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far!
…hange api img_shape -> img_size.
Co-authored-by: Andrewwango <[email protected]>
Co-authored-by: Andrewwango <[email protected]>
tachella
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks very nice!
some minor comments
Andrewwango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor, but apart from these LGTM and happy to approve once everything resolved
Co-authored-by: Andrewwango <[email protected]>
|
@romainvo Please can you check out the bugs in the workflows? |
I have implemented a
TomographyWithAstraoperator using the https://astra-toolbox.com/. It uses the GPULink functionality of astra to share the underlying CUDA memory of torch.Tensor and arrays used byastra. By wrapping astra, the operator supports 2d geometries (parallel and fanbeam) as well as 3d (parallel and conebeam).Astra can be installed easily with
conda install -c astra-toolbox -c nvidia astra-toolbox.The contribution consists in two main classes:
deepinv.physics.functional.astra.XrayTransformobject, which wraps the astra-computation, both forward and adjoint computation, with torch.Tensor as inputs.deepinv.physics.TomographyWithAstraLinearPhysics operator, which instanciates an XrayTransform as attribute (similar to how the Radon module is used). The calls to XrayTransform are wrapped in a customtorch.autograd.Function(AutogradTransform in astra.py) to make the computation ofA()andA_adjoint()differentiable with torch.The operator is more memory efficient, though slower for batched computations in parallel 2d. This is because ASTRA does not handle batched computations, therefore the custom autograd.Function processes batch elements sequentially. It is a priori, not easily vmappable (https://pytorch.org/docs/stable/notes/extending.func.html) because the XrayTransform needs to access pointers of batch elements, which is not possible for Tensors produced during vmap.
I have also adapted the following examples, to check for an
astra-toolboxinstall and adapt the CT operator used automatically.examples/plug-and-play/demo_vanilla_PnP.pyexamples/patch-priors/demo_patch_priors_CT.pyI haven't touched the learned primal-dual example which runs significantly slower while using the
astraoperator.Other changes:
AbstractFilermodule indeepinv.physics.functional.radon.pyto handle sinogram data for both theTomographyoperator and theTomographyWithAstraoperator.Test:
pytestifastrais not installed.Checks to be done before submitting your PR
python3 -m pytest tests/runs successfully.black .runs successfully.make htmlruns successfully (in thedocs/directory).