Skip to content

Import tensorflow.keras (tf_keras) when TF_USE_LEGACY_KERAS #1040

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions keras_tuner/backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import keras
import os


def _multi_backend():
if os.environ.get("TF_USE_LEGACY_KERAS", None) in ("true", "True", "1"):
from tensorflow as keras
_MULTI_BACKEND = False
else:
import keras
version_fn = getattr(keras, "version", None)
return version_fn and version_fn().startswith("3.")


_MULTI_BACKEND = _multi_backend()
_MULTI_BACKEND = version_fn and version_fn().startswith("3.")


def multi_backend():
Expand Down