-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
feat(layers): Migrate RandomChoice and RandomApply layers from keras-cv to keras #20752
base: master
Are you sure you want to change the base?
feat(layers): Migrate RandomChoice and RandomApply layers from keras-cv to keras #20752
Conversation
- Added RandomChoice and RandomApply layers to keras.layers.preprocessing.image_preprocessing. - Implemented necessary transform methods (transform_images, transform_labels, transform_bounding_boxes, transform_segmentation_masks) to comply with BaseImagePreprocessingLayer. - Updated tests to ensure compatibility with keras and fix failing test cases. - Added support for batchwise processing, auto-vectorization, and random seed control.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #20752 +/- ##
==========================================
+ Coverage 81.94% 81.96% +0.02%
==========================================
Files 553 561 +8
Lines 51536 52424 +888
Branches 7978 8104 +126
==========================================
+ Hits 42231 42970 +739
- Misses 7363 7475 +112
- Partials 1942 1979 +37
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
…andomApply and RandomChoice layers - Updated layers to handle JAX backend-specific behavior and avoid tracer leaks. - Updated tests to use backend-agnostic Keras operations. - Skipped JAX-specific tests with TODO to investigate further. - Removed Tensorflow-specific dependencies for better backend compatibility.
keras/src/layers/preprocessing/image_preprocessing/random_apply_test.py
Outdated
Show resolved
Hide resolved
- Add handling for layers with get_random_transformation method in both RandomApply and RandomChoice preprocessing layers - Fix seed handling in RandomChoice to ensure consistent behavior across backends - Remove JAX-specific test skipmarks after addressing tracer errors
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
- Simplified docstrings. - Removed copyright headers from files. - Refactored RandomApply and RandomChoice. - Streamlined transformation logic and improved overall code organization. - Eliminated redundant backend-specific code paths.
@fchollet, would love your thoughts on these changes whenever you get a chance, thanks! Also please do look into the comment I've left unresolved regarding whether it should inherit from |
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 the PR!
@innat do you want to review?
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
Sure, I'll review it. Thanks for tagging me. |
keras/src/layers/preprocessing/image_preprocessing/random_choice.py
Outdated
Show resolved
Hide resolved
- removed unused auto_vectorize parameter from both layers - shortened docstring headers to fit on one line - added backticks around boolean keywords (True, False) in docstrings - fixed incorrect transform methods (bounding_boxes, labels, segmentation_masks) to return inputs unchanged - removed unnecessary transformation methods from RandomChoice for consistency with original implementation
@fchollet |
@fchollet please do look into the changes, thanks! |
I am not seeing anything to approve? I was under the impression anyone could add a review.
Looking now! |
Hi @fchollet, |
Please fix the code format by running |
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
keras/src/layers/preprocessing/image_preprocessing/random_apply.py
Outdated
Show resolved
Hide resolved
I am not even sure we should be brining over these layers in the first place, to be honest. |
I'd love to keep working on these layers if they are needed in the codebase; if not, I guess closing the PR without merging it is, but I've proceeded to implement the fixes in any case.
Seems the changes need to be made in both |
- Add proper transformation of images, labels, and bounding boxes - Extract _should_augment method for cleaner random decision logic and move utility function to test file
Hi, is there a reason this PR is not moving forward? Please do clarify, thanks! |
RandomChoice
andRandomApply
layers tokeras.layers.preprocessing.image_preprocessing
transform_images
,transform_labels
,transform_bounding_boxes
,transform_segmentation_masks
) to comply withBaseImagePreprocessingLayer