Description
Describe the bug
keras_tuner.src.errors.FatalTypeError: Expected the model-building function, or HyperModel.build() to return a valid Keras Model instance. Received: <tf_keras.src.engine.functional.Functional object at 0x7fe49809f8d0> of type <class 'tf_keras.src.engine.functional.Functional'>
To Reproduce
I get the error when trying to do a tuner.search()
.
I'm using tensorflow==2.18.0
with os.environ["TF_USE_LEGACY_KERAS"] = "1"
and also install tf_keras==2.18.0
, as described in: https://keras.io/getting_started/#tensorflow--keras-2-backwards-compatibility
I'm not ready to move to keras v3, because I'm also using tf-gnn, which does not support Keras v3 yet: https://github.com/tensorflow/gnn/blob/v1.0.3/tensorflow_gnn/docs/guide/keras_version.md#for-tensorflow-216-and-up
Expected behavior
Tuner works with legacy keras (tf_keras)
Additional context
I think one of the problems is:
keras-tuner/keras_tuner/backend/config.py
Line 15 in 417e5b5
It always import keras
, which will import keras v3 when tensorflow 2.16+ is installed.
Would you like to help us fix it?
Yes.