Adding superglue fast image processing#41394
Conversation
…function refactor
… torch first method
|
cc @yonigozlan |
yonigozlan
left a comment
There was a problem hiding this comment.
Hi @AlphaOrOmega, thanks for working on this!
Please have a thorough look at the guide in this PR on how to implement a fast image processor correctly: #36978
You can also have a look at image_processing_efficientloftr_fast.py, as it should be almost identical to this image processor!
…implementation' into fast_image_processing_superglue_implementation
|
Hi @yonigozlan, Thank you for the feedback, the referenced processor was indeed very close to the one I implemented, so I re-used relevant code and ensured the logic was still here, Could you please review the recent changes ? Thank you |
…ng_superglue_implementation
yonigozlan
left a comment
There was a problem hiding this comment.
Thanks a lot @AlphaOrOmega for working on this! Just added a commit to use modular for efficientloftr using this new image processor. Let's wait for the CI to pass then we'll merge!
…s://github.com/AlphaOrOmega/transformers into fast_image_processing_superglue_implementation
|
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. |
…s://github.com/AlphaOrOmega/transformers into fast_image_processing_superglue_implementation
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto, efficientloftr, lightglue, superglue |
* Default implementation - no time improvement * Improved implementation - apparently 2 times faster with only simple function refactor * elementary torch first approach, still need further implementation of torch first method * torch-first approach finished * refactor processor * refactor test * partial doc update * EfficientLoFTRImageProcessorFast based implementation * EfficientLoFTRImageProcessorFast based implementation * Logic checked - Test Passed - Validated execution speed * use modular for efficientloftr * fix import --------- Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co> Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com>
* Default implementation - no time improvement * Improved implementation - apparently 2 times faster with only simple function refactor * elementary torch first approach, still need further implementation of torch first method * torch-first approach finished * refactor processor * refactor test * partial doc update * EfficientLoFTRImageProcessorFast based implementation * EfficientLoFTRImageProcessorFast based implementation * Logic checked - Test Passed - Validated execution speed * use modular for efficientloftr * fix import --------- Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co> Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com>
What does this PR do?
TLDR :
This PR aims to translate the features of the class
SuperGlueImageProcessorin the fast equivalent classSuperGlueImageProcessorFast.The implementation heavily follows the standard implementation but reduces memory consumption and about 3 times the execution speed on my hardware.
The implementation mostly refactor the image formatting in the
preprocessingstep, notably by using torch tensors instead of PIL or Numpy.Test Performed
RUN_SLOW=1 python -m pytest tests/models/superglue/test_image_processing_superglue.py
With an additional test based on the default processor tester (this test has not to be included in the repo) :
By reviewing the flame graph, I noticed the improvement in every
__calls__made to the fast version.Callers of the old processor, and the full execution time of the method:

The equivalent but with the fast processor:

Some calls made during the test passes directly to the preprocess function, without passing by the


__call__one, I am including them as well:Slow
Fast
Before submitting
Pull Request section?
to it if that's the case.
link : [Contributions Welcome] Add Fast Image Processors [Contributions Welcome] Add Fast Image Processors #36978 (comment)
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Thank you for reviewing my PR @yonigozlan (or anyone else :) )