Skip to content

tensorflow-model-optimization fails to import in official tensorflow:2.15.0 Docker image due to TF_USE_LEGACY_KERAS=1 and missing tf_keras #1272

Description

@Lao666-bot

When using the official TensorFlow Docker image tensorflow/tensorflow:2.15.0, the environment variable TF_USE_LEGACY_KERAS is preset to 1 (True). This causes tensorflow-model-optimization (tfmot) to fail with an ImportError because it expects tf_keras to be installed.

Attempting to install tf_keras leads to an automatic upgrade of TensorFlow to 2.21+, which breaks compatibility with tfmot (which is designed for TensorFlow 2.15).

  1. Pull the official image:
    docker pull tensorflow/tensorflow:2.15.0
    docker run -it tensorflow/tensorflow:2.15.0 bash
    pip install tensorflow-model-optimization==0.8.0
    python -c "import tensorflow_model_optimization as tfmot"

The import fails with:
ImportError: Keras cannot be imported. Check that it is installed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions