-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
🚨🚨🚨 [SuperPoint] Fix keypoint coordinate output and add post processing #33200
Conversation
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 fixing and adding this method!
Overall looks good - just a few things to add / update
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
# Convert to relative coordinates | ||
keypoints = keypoints / torch.tensor([width, height], device=keypoints.device) |
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.
Technically a breaking change - but as this is more of a fix, I think it's OK
…and switched from opencv to matplotlib
…st_tf" This reverts commit 39b32a2.
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
Co-authored-by: NielsRogge <48327001+NielsRogge@users.noreply.github.com>
…e choice in post process method
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 iterating!
Mostly small comments. Main one is about the indexing on image_sizes
in the post-processing method
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
@amyeroberts comments addressed, tests are passing, let me know if I can do a final rebase for the merge |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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 working on this! Just some minor comments
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
… statement and changed tests results to reflect changes to SuperPoint from absolute keypoints coordinates to relative
@qubvel thanks for the review, I've addressed your comments. I initially forgot to change the tests to reflect the changes in terms of SuperPoint's outputs, so this is also fixed. Let me know if there is anything else to do |
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 quick iteration, a few more comments
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
src/transformers/models/superpoint/image_processing_superpoint.py
Outdated
Show resolved
Hide resolved
@@ -260,7 +260,7 @@ def test_inference(self): | |||
inputs = preprocessor(images=images, return_tensors="pt").to(torch_device) | |||
with torch.no_grad(): | |||
outputs = model(**inputs) | |||
expected_number_keypoints_image0 = 567 |
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.
Wondering why the number of keypoints changed :)
…ocess_keypoint_detection
…oder class name and added relative (x, y) coordinates information to its method
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.
Thank you for the fixes! Test diff looks fine now 👍
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, looks good to me now!
cc @ArthurZucker for final review
Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
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.
Feel free to merge if ready for you @qubvel 🤗
Hello, I was following this PR and curious that is it going to merge or any change still require ? |
Hi @onuralpszr , |
@sbucaille thanks a lot for your contribution! |
…ng (huggingface#33200) * feat: Added int conversion and unwrapping * test: added tests for post_process_keypoint_detection of SuperPointImageProcessor * docs: changed docs to include post_process_keypoint_detection method and switched from opencv to matplotlib * test: changed test to not depend on SuperPointModel forward * test: added missing require_torch decorator * docs: changed pyplot parameters for the keypoints to be more visible in the example * tests: changed import torch location to make test_flax and test_tf * Revert "tests: changed import torch location to make test_flax and test_tf" This reverts commit 39b32a2. * tests: fixed import * chore: applied suggestions from code review Co-authored-by: NielsRogge <48327001+NielsRogge@users.noreply.github.com> * tests: fixed import * tests: fixed import (bis) * tests: fixed import (ter) * feat: added choice of type for target_size and changed tests accordingly * docs: updated code snippet to reflect the addition of target size type choice in post process method * tests: fixed imports (...) * tests: fixed imports (...) * style: formatting file * docs: fixed typo from image[0] to image.size[0] * docs: added output image and fixed some tests * Update docs/source/en/model_doc/superpoint.md Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com> * fix: included SuperPointKeypointDescriptionOutput in TYPE_CHECKING if statement and changed tests results to reflect changes to SuperPoint from absolute keypoints coordinates to relative * docs: changed SuperPoint's docs to print output instead of just accessing * style: applied make style * docs: added missing output type and precision in docstring of post_process_keypoint_detection * perf: deleted loop to perform keypoint conversion in one statement * fix: moved keypoint conversion at the end of model forward * docs: changed SuperPointInterestPointDecoder to SuperPointKeypointDecoder class name and added relative (x, y) coordinates information to its method * fix: changed type hint * refactor: removed unnecessary brackets * revert: SuperPointKeypointDecoder to SuperPointInterestPointDecoder * Update docs/source/en/model_doc/superpoint.md Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com> --------- Co-authored-by: Steven Bucaille <steven.bucaille@buawei.com> Co-authored-by: NielsRogge <48327001+NielsRogge@users.noreply.github.com> Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
What does this PR do?
There is a bug highlighted by @merveenoyan where SuperPoint returns absolute keypoint coordinates at a wrong scale.
For example, an image of size (1000, 1000) will first be resized into (640, 480) by the image processor but SuperPoint will output keypoint coordinates between 0 and 640 for x and 0 and 480 for y.
This PR fixes this bug by returning keypoints in relative coordinates out of the SuperPoint forward method.
An additional
post_process_keypoint_detection
is added to theSuperPointImageProcessor
to cast the keypoint coordinates into the original image sizes.I also added an "unwrapping" logic where the output will be a list of
keypoints, scores, descriptors
for each image so that the user don't have to deal with the current mask mechanism. This is conditionned by a boolean argument in the signature.I have not finished all the details but most of the implementation is there and I will add tests tomorrow but at least the PR is open as I promised Merve☺️
Fixes #33825
Before submitting
to it if that's the case.
-> On Slack
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@amyeroberts @NielsRogge @merveenoyan