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

[WiP] Switch Keras2 to tf_keras #2127

Closed

Conversation

sampathweb
Copy link
Collaborator

Switches from tensorflow import keras to import tf_keras as keras when using keras 2 workflow.

We currently use TensorFlow 2.13 in release (for Waymo?). If we can bump it to 2.14, we can switch to tf_keras.
https://github.com/keras-team/keras-cv/blob/master/.github/workflows/actions.yml#L36

Copy link
Member

@fchollet fchollet left a 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! We should also update the logic in keras_cv/backend/config.py to resolve the default "multi-backend" value.

IMO:

  • Switch the name to something more explicit like "keras_3"
  • Make it configurable by both the .json and and env variable
  • To find the default value to use:
  1. import keras, check if Keras 3. If so, use keras_3=True as default.
  2. Else use Keras 2.

Also, we might want to drop keras_core support after the keras 3 release.

import tf_keras as keras
except ImportError:
raise ImportError(
"Keras 2 requires the `tf_keras` package."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Using KerasCV with Keras 2"

@@ -52,7 +52,13 @@

keras.backend.name_scope = keras.name_scope
else:
from tensorflow import keras
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to be more conservative to enable people to use Keras 2 via tf.keras without having to install tf_keras:

  1. from tensorflow import keras
  2. if not hasattr(keras, "version"): then tf.keras is Keras 2. We use keras from TF.
  3. else: try to import tf_keras
  4. if not available: raise

@mattdangerw
Copy link
Member

I think as discussed on chat, we can probably close this one in favor of #2132

@mattdangerw
Copy link
Member

Closing in favor of #2132

@mattdangerw mattdangerw closed this Nov 8, 2023
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.

3 participants