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

Vectorized implementation of RandomColorDegeneration and Equalization preprocessing layers #2214

Conversation

sup3rgiu
Copy link
Contributor

@sup3rgiu sup3rgiu commented Dec 6, 2023

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, while RandomColorDegeneration 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
image

Equalization:
image
image

The output of the Equalization layer is deterministic, so the two implementations (original vs vectorized) can be compared with np.allclose(output_original, output_vectorized), which returns True.

Source: https://colab.research.google.com/drive/1t5b4a11ae3HWxUoyL-R50E2z8dkNSQYP

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue? Please add a link
    to it if that's the case.
  • Did you write any new necessary tests?
  • If this adds a new model, can you run a few training steps on TPU in Colab to ensure that no XLA incompatible OP are used?

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.

@divyashreepathihalli
Copy link
Collaborator

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).

@sup3rgiu
Copy link
Contributor Author

sup3rgiu commented Dec 8, 2023

I fixed the implementation to support RaggedTensors. The test should be ok now.

New colab if needed: https://colab.research.google.com/drive/1uhuApsP8G6k0FYsN4Pw5wDx6X2aptTaN

@divyashreepathihalli
Copy link
Collaborator

/gcbrun

@divyashreepathihalli
Copy link
Collaborator

Thank you!!

@divyashreepathihalli divyashreepathihalli merged commit 25cb3a1 into keras-team:master Dec 8, 2023
6 of 9 checks passed
divyashreepathihalli pushed a commit that referenced this pull request Dec 11, 2023
* 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>
yuvraj-wale pushed a commit to yuvraj-wale/keras-cv that referenced this pull request Feb 8, 2024
… preprocessing layers (keras-team#2214)

* Vectorize RandomColorDegeneration

* Vectorize Equalization

* Vectorize Equalization

* Fix Equalization for ragged input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RandomColorDegeneration and Equalization are not implemented as vectorized operations
2 participants