-
Notifications
You must be signed in to change notification settings - Fork 325
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
Vectorized implementation of RandomColorDegeneration and Equalization preprocessing layers #2214
Vectorized implementation of RandomColorDegeneration and Equalization preprocessing layers #2214
Conversation
There is also one failing test for ragged input - keras_cv/layers/preprocessing/ragged_image_test.py::RaggedImageTest::test_preserves_ragged_status_Equalization - ValueError: Exception encountered when calling layer 'equalization' (type Equalization). |
I fixed the implementation to support RaggedTensors. The test should be ok now. New colab if needed: https://colab.research.google.com/drive/1uhuApsP8G6k0FYsN4Pw5wDx6X2aptTaN |
/gcbrun |
Thank you!! |
* Adds Kokoro GPU Tests (#2224) * Adds Kokoro tests * Add Kokoro Tests * Update random_cutout.py to be a subclass of VectorizedBaseImageAugmentationLayer (#2123) * Update random_cutout.py Make RandomCutout a subclass of VectorizedBaseImageAugmentationLayer * Fix RandomCutout for ragged inputs * Fix typo and style * Vectorized implementation of RandomColorDegeneration and Equalization preprocessing layers (#2214) * Vectorize RandomColorDegeneration * Vectorize Equalization * Vectorize Equalization * Fix Equalization for ragged input --------- Co-authored-by: Ramesh Sampath <1437573+sampathweb@users.noreply.github.com> Co-authored-by: SUPERGIU <supergiu@outlook.com>
… preprocessing layers (keras-team#2214) * Vectorize RandomColorDegeneration * Vectorize Equalization * Vectorize Equalization * Fix Equalization for ragged input
What does this PR do?
Fixes #2120 (issue)
As Keras_CV==0.7.1, RandomColorDegeneration and Equalization preprocessing layers are not subclasses of
VectorizedBaseImageAugmentationLayer
, thus resulting in a slow forward pass.The vectorized implementation of
RandomColorDegeneration
is quite straightforward, whileRandomColorDegeneration
has a potential bottleneck represented by tf.histogram_fixed_width.In this pull request I propose an implementation for both layers.
As requested in #2120, these are the demo outputs:
RandomColorDegeneration:
![image](https://private-user-images.githubusercontent.com/7725068/288460076-444db184-5e94-4ede-867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ExMzI5NWUzYjQ2ZWJmMzQxMmNiNzM1YWQ1OWFmOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.CKWbq4Wgh_S5q_-qUi8pPA29JCIVFUdLbw1hnPwWHhk)
![image](https://private-user-images.githubusercontent.com/7725068/288460161-a5d4aa10-6b7d-4dc1-8974-256da7507486.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwODQ5ODgsIm5iZiI6MTcyNTA4NDY4OCwicGF0aCI6Ii83NzI1MDY4LzI4ODQ2MDE2MS1hNWQ0YWExMC02YjdkLTRkYzEtODk3NC0yNTZkYTc1MDc0ODYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgzMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MzFUMDYxMTI4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTUxMjA3ZjlhY2M4M2UxNjk4NmMxYTlhN2MyM2IwZWQ3ODRiOTYyYWQwZDFjMjJmN2ZhOTM3NWRlMjNhNWM0ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.w8P5CmU_KHdCF4xXxKRbGbpImDX9XOSGVsTX7VBVOs0)
The output of the
Equalization
layer is deterministic, so the two implementations (original vs vectorized) can be compared withnp.allclose(output_original, output_vectorized)
, which returnsTrue
.Source: https://colab.research.google.com/drive/1t5b4a11ae3HWxUoyL-R50E2z8dkNSQYP
Before submitting
Pull Request section?
to it if that's the case.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.