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

Add keras.ops.rot90 for tf.image.rot90 #20723

Closed
innat opened this issue Jan 4, 2025 · 4 comments · Fixed by #20745
Closed

Add keras.ops.rot90 for tf.image.rot90 #20723

innat opened this issue Jan 4, 2025 · 4 comments · Fixed by #20745
Assignees
Labels
type:feature The user is asking for a new feature.

Comments

@innat
Copy link

innat commented Jan 4, 2025

tf api: https://www.tensorflow.org/api_docs/python/tf/image/rot90
torch api: https://pytorch.org/docs/stable/generated/torch.rot90.html
jax api: https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.rot90.html

In keras, it provides RandomRotation and probably not replacable with tf.image.90.

@innat innat changed the title Add keras.ops.rot90* for tf.image.rot90 Add keras.ops.rot90 for tf.image.rot90 Jan 4, 2025
@fchollet
Copy link
Collaborator

fchollet commented Jan 4, 2025

It is a numpy op: https://numpy.org/doc/stable/reference/generated/numpy.rot90.html

Any op that is in numpy is in-scope for inclusion in Keras. Since there are already built-in functions for it in all backends, adding it should be easy. Are you able to open a PR?

@innat
Copy link
Author

innat commented Jan 4, 2025

I'm working on a related topic and can submit a PR if that helps.

@fchollet
Copy link
Collaborator

fchollet commented Jan 4, 2025

Please do.

@harshaljanjani
Copy link
Contributor

This is my first time contributing to this repo, and I’ve just raised a pull request for the issue. Let me know if there’s anything I need to fix or improve, I’d be happy to make changes!
Looking forward to your feedback.

fchollet pushed a commit that referenced this issue Jan 13, 2025
* feat(ops): Add keras.ops.image.rot90 operation

Adds a new operation to rotate tensors by 90 degrees in the specified plane:
- Implements rot90 operation in keras.ops.image module
- Adds support for multiple rotations (k parameter) and custom axes
- Matches numpy.rot90 behavior and API for consistency
- Adds comprehensive test coverage including batch images support
- Handles input validation for tensor dimensions and axes
- Supports symbolic tensor execution
The operation follows the same interface as numpy.rot90 and tf.image.rot90:
rot90(array, k=1, axes=(0, 1))

* feat: add JAX, NumPy and PyTorch backends for rot90

Add implementations of rot90() for multiple backend frameworks:
- JAX backend implementation
- NumPy backend implementation
- PyTorch backend implementation

* Move rot90 from image to numpy ops

Move rot90 operation to numpy.py files in backend implementations since it's a numpy op (https://numpy.org/doc/stable/reference/generated/numpy.rot90.html). Now exported as both keras.ops.rot90 and keras.ops.numpy.rot90.

* Fix dtype conflict in PyTorch backend's rot90 function

Resolved the 'Invalid dtype: object' error by explicitly using  to avoid naming conflicts with the custom  function.

* Replace experimental NumPy rot90 with core TF ops

Replace tf.experimental.numpy.rot90 with core TF ops for XLA compatibility.
Use convert_to_tensor for input handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature The user is asking for a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants