Skip to content

Commit

Permalink
Fix Keras 3 version check (keras-team#2191)
Browse files Browse the repository at this point in the history
* Fix Keras 3 version check

* Fix Keras 3 version check

* Fix Keras 3 version check

* Raise error if Keras is not compatible with TF
  • Loading branch information
sampathweb authored and yuvraj-wale committed Feb 8, 2024
1 parent e74881a commit 8bf0ec9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions keras_cv/backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@

def detect_if_tensorflow_uses_keras_3():
# We follow the version of keras that tensorflow is configured to use.
from tensorflow import keras

# Note that only recent versions of keras have a `version()` function.
if hasattr(keras, "version") and keras.version().startswith("3."):
return True
try:
from tensorflow import keras

# Note that only recent versions of keras have a `version()` function.
if hasattr(keras, "version") and keras.version().startswith("3."):
return True
except:
raise ValueError(
"Unable to import `keras` with `tensorflow`. Please check your "
"Keras and Tensorflow version are compatible; Keras 3 requires "
"TensorFlow 2.15 or later. See keras.io/getting_started for more "
"information on installing Keras."
)

# No `keras.version()` means we are on an old version of keras.
return False
Expand Down

0 comments on commit 8bf0ec9

Please sign in to comment.