-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Add ops.image.scale_and_translate
.
#21577
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
Add ops.image.scale_and_translate
.
#21577
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.
Summary of Changes
Hello @james77777778, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new ops.image.scale_and_translate
operation to the Keras library. This operation is designed to provide robust image scaling and translation capabilities, particularly useful for tasks such as depth estimation where precise interpolation with align_corners=True
behavior is required. The implementation is fully integrated across Keras's multi-backend system, ensuring consistent behavior and performance across JAX, NumPy, TensorFlow, and Torch. This addition enhances Keras's image processing toolkit, offering a flexible and performant solution for common image manipulation needs in deep learning workflows.
Highlights
- New Image Operation: Introduces a new image operation,
ops.image.scale_and_translate
, which provides functionality similar totorch.nn.functional.interpolate
withalign_corners=True
, crucial for applications like depth estimation models. - Multi-Backend Implementation: The new operation is implemented across JAX, NumPy, TensorFlow, and Torch backends, ensuring broad compatibility and leveraging backend-specific optimizations.
- Code Refactoring and Internalization: Refactored several internal helper functions (e.g.,
_compute_weight_mat
,_compute_homography_matrix
, and kernel functions) by prefixing them with an underscore, clearly indicating their private nature within the backend implementations. - Improved Test Coverage: Comprehensive unit tests have been added for the
scale_and_translate
operation, covering symbolic and static shape inference, as well as behavioral correctness across various interpolation methods and antialiasing settings.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a new image operation, ops.image.scale_and_translate
, which is a useful addition, especially for functionalities similar to torch.nn.functional.interpolate
with align_corners=True
. The implementations for JAX, TensorFlow, and PyTorch backends are well-structured and follow the patterns of existing operations. The tests are comprehensive, covering symbolic execution and correctness against a reference implementation.
I've identified a bug in the NumPy backend's _resize
function that was introduced during refactoring, which would break existing resize
functionality. I've also suggested a clarification in the docstring for the new scale_and_translate
operation to improve clarity for users. Please see the detailed comments for suggestions.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #21577 +/- ##
========================================
Coverage 82.75% 82.76%
========================================
Files 567 567
Lines 56531 56694 +163
Branches 8824 8841 +17
========================================
+ Hits 46785 46920 +135
- Misses 7585 7602 +17
- Partials 2161 2172 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
/gemini review |
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.
Code Review
This pull request introduces a new image operation, ops.image.scale_and_translate
, which is useful for tasks like depth estimation. The implementation is added for JAX, TensorFlow, and NumPy backends, with a NotImplementedError
for OpenVINO. The changes also include some nice refactoring, such as moving constants to the top of backend files and improving helper functions. The new operation is well-tested.
I have one minor suggestion to improve the clarity of the docstring for the new function. Otherwise, the changes look great.
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.
LGTM, thank you for the contribution!
@@ -14,6 +14,34 @@ | |||
"lanczos5", | |||
"bicubic", | |||
) | |||
AFFINE_TRANSFORM_INTERPOLATIONS = { # map to order |
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.
Nice, this is clearer.
This op is useful if we want to perform the same functionality as
torch.nn.functional.interpolate
withalign_corners=True
.Some depth estimation models require this functionality.
Here is an example:
The benchmark:
(1, 256, 256, 64)
to(1, 128, 128, 64)
benchmark.py