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

Projective transform for equivariant imaging #173

Merged
merged 30 commits into from
Jun 14, 2024

Conversation

Andrewwango
Copy link
Collaborator

@Andrewwango Andrewwango commented Mar 15, 2024

This PR introduces the projective transformation, or homography, an image transformation available for self-supervised learning using equivariant imaging. The transformation is implemented at deepinv.transform.Homography.

I've also implemented a few subgroups of transformations, including deepinv.transform.projective.Affine, deepinv.transform.projective.Similarity and deepinv.transform.projective.Euclidean transformations, which may also be useful in some use-cases.

This was introduced in our recent paper Perspective-Equivariant Imaging: an Unsupervised Framework for Multispectral Pansharpening, as the homography provides a richer group of transformations and so provides better performance for equivariant imaging in camera-based imaging scenarios such as satellite imaging.

See further demos of this functionality at this webpage notebook.

Note this adds kornia as a dependency, but happy to make it optional dependency instead if needed.

Checks to be done before submitting your PR

  • python3 -m pytest tests/ runs successfully.
  • black . runs successfully.
  • make html runs successfully (in the docs/ directory).
  • Updated docstrings related to the changes (as applicable).
  • Added an entry to the CHANGELOG.rst.

@tachella
Copy link
Contributor

Hey Andrew,

This would be a nice contribution! I think it would be good to document all of the transforms, and add them in the documentation.

I can have a look once the tests are passing!

@Andrewwango Andrewwango marked this pull request as draft April 3, 2024 10:24
@Andrewwango Andrewwango changed the title Add projective transform for equivariant imaging Draft: projective transform for equivariant imaging Apr 3, 2024
@Andrewwango Andrewwango changed the title Draft: projective transform for equivariant imaging Projective transform for equivariant imaging Apr 29, 2024
@Andrewwango Andrewwango marked this pull request as ready for review April 29, 2024 13:21
@samuro95
Copy link
Collaborator

I am in favor of making the kornia dependency optional, especially because it is used only once, and only in case the transform is applied to tensors. @tachella what do you think ?

Copy link

codecov bot commented May 29, 2024

Codecov Report

Attention: Patch coverage is 84.21053% with 18 lines in your changes missing coverage. Please review.

Project coverage is 66.70%. Comparing base (2e138eb) to head (709c629).
Report is 31 commits behind head on main.

Current head 709c629 differs from pull request most recent head 7a67432

Please upload reports for the commit 7a67432 to get more accurate results.

Files Patch % Lines
deepinv/transform/projective.py 82.85% 10 Missing and 2 partials ⚠️
deepinv/tests/test_transform.py 93.33% 1 Missing and 1 partial ⚠️
deepinv/training/testing.py 33.33% 2 Missing ⚠️
deepinv/training/trainer.py 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #173      +/-   ##
==========================================
- Coverage   76.01%   66.70%   -9.32%     
==========================================
  Files         101      124      +23     
  Lines        7481     8782    +1301     
  Branches     1013     1264     +251     
==========================================
+ Hits         5687     5858     +171     
- Misses       1474     2536    +1062     
- Partials      320      388      +68     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Andrewwango
Copy link
Collaborator Author

I am in favor of making the kornia dependency optional, especially because it is used only once, and only in case the transform is applied to tensors. @tachella what do you think ?

How do I add it as an optional dependency?

@tachella
Copy link
Contributor

tachella commented Jun 4, 2024

I am in favor of making the kornia dependency optional, especially because it is used only once, and only in case the transform is applied to tensors. @tachella what do you think ?

How do I add it as an optional dependency?

You can do it in the same way as bm3d for example, see

@Andrewwango Andrewwango mentioned this pull request Jun 7, 2024
5 tasks
Copy link
Contributor

@tachella tachella left a comment

Choose a reason for hiding this comment

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

The PR looks great, I just found a few details in the docstrings to correct: at the moment the example snippets will not run since the :: indicator for code is not recognized by doctest.

save_folder_curve.mkdir(parents=True, exist_ok=True)

if plot_images:
(
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you apply these changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe that was @samuro95 ?

deepinv/training/trainer.py Outdated Show resolved Hide resolved
deepinv/transform/projective.py Outdated Show resolved Hide resolved
deepinv/transform/projective.py Outdated Show resolved Hide resolved
deepinv/transform/projective.py Outdated Show resolved Hide resolved
deepinv/transform/projective.py Outdated Show resolved Hide resolved
deepinv/transform/projective.py Outdated Show resolved Hide resolved
deepinv/transform/projective.py Outdated Show resolved Hide resolved

physics = dinv.physics.Inpainting((3, 256, 256), mask=0.6, device=device)

download_and_extract_archive(
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please update to the Urban100HR class added in a recent PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This increases demo runtime by ~1min as the current deepinv Urban100HR is much bigger than the HF Urban100 I'm using. I could create an issue?

Copy link
Contributor

@tachella tachella left a comment

Choose a reason for hiding this comment

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

many thanks @Andrewwango for this PR - everything looks good to me

@tachella tachella merged commit 10ed631 into deepinv:main Jun 14, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants