Giter Club home page Giter Club logo

Comments (9)

robertbcalhoun avatar robertbcalhoun commented on June 2, 2024 1

I'm having the same issue; attempting import tensorflow_hub (which imports tf_keras) fails with this error:

AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' 
has no attribute 'register_load_context_function'.
   Did you mean: 'register_call_context_function'?

This seems to be the result of some in-process refactoring of tf_keras/src/saving/legacy/saved_model that has since been completed, so presumably a later release will fix.

At the moment, the default installs of tensorflow and tensorflow_hub install tensorflow 2.16.0rc0 and tf-keras 2.15:

$ # start with new venv
$ python -m pip freeze | grep -e tensor -e keras
$ python -m pip install tensorflow keras tf-keras --no-cache-dir > /dev/null
$ python -m pip freeze | grep -e tensor -e keras
keras==3.0.5
tensorboard==2.16.2
tensorboard-data-server==0.7.2
tensorflow==2.16.0rc0
tf-keras==2.15.0

I've been trying to work around the incompatibility by reverting to a prior tensorflow release. I expect to be able to install out-of-date versions via pip like this:

$ python -m pip index versions tf-keras
WARNING: pip index is currently an experimental command.
 It may be removed/changed in a future release without prior warning.
tf-keras (2.15.0)
Available versions: 2.15.0, 2.14.1
$ python -m pip install tf-keras==2.14.1
Collecting tf-keras==2.14.1
  Using cached tf_keras-2.14.1-py3-none-any.whl.metadata (1.6 kB)
Using cached tf_keras-2.14.1-py3-none-any.whl (1.7 MB)
Installing collected packages: tf-keras
Successfully installed tf-keras-2.14.1

However, this approach is not working with tensorflow. I don't see anything obviously broken at PyPI, but I've not been able to install prior tensorflow releases via pip.

$ python -m pip install tensorflow==2.15.0
ERROR: Could not find a version that satisfies the requirement tensorflow==2.15.0 (from versions: 2.16.0rc0)
ERROR: No matching distribution found for tensorflow==2.15.0
$ python -m pip index versions tensorflow
WARNING: pip index is currently an experimental command. 
It may be removed/changed in a future release without prior warning.
ERROR: No matching distribution found for tensorflow

from tf-keras.

tilakrayal avatar tilakrayal commented on June 2, 2024

@MaxiBoether,
Could you please try to replace it from tensorflow import keras with import tf_keras as keras. Kindly find the gist for the reference.

Thank you!

from tf-keras.

MaxiBoether avatar MaxiBoether commented on June 2, 2024

Thanks for the swift response. This leads to the same error as outlined. Note that I tried two things: import tensorflow.keras (which is equivalent to from tensorflow import keras) which imports keras 3 as expected, but importing import tf_keras (it shouldn't matter whether I add as keras as requested since that's just the imported module name) fails. My goal is to import the legacy Keras 2 in a tf2.16 environment

from tf-keras.

MaxiBoether avatar MaxiBoether commented on June 2, 2024

Okay, I know what the issue is: By default (at least on my mac in a clean conda env), pip install tensorflow installs tf2.16, and pip install tf_keras installs tf_keras==2.15. On colab, pip install tensorflow defaults to v2.15. Since I just ran pip install tensorflow tf_keras, we run into this issue.

The version mismatch (if enforced on colab) leads to this error.

from tf-keras.

robertbcalhoun avatar robertbcalhoun commented on June 2, 2024

It appears 2.16.0rc0 is a pre-release version of tensorflow. Running the same commands on a different host (ubuntu under wsl) gives me 2.15.0.post1, which is what I would expect based on PyPI:

$ python -m pip index versions tensorflow
tensorflow (2.15.0.post1)
Available versions: 2.15.0.post1, 2.15.0, 2.14.1, 2.14.0, 2.13.1, 2.13.0, 2.12.1, 2.12.0, 2.11.1, 2.11.0, 2.10.1, 2.10.0, 2.9.3, 2.9.2, 2.9.1, 2.9.0, 2.8.4, 2.8.3, 2.8.2, 2.8.1, 2.8.0
  INSTALLED: 2.15.0.post1
  LATEST:    2.15.0.post1

Overall:

$ python -m pip freeze | grep -e tensor -e keras
keras==2.15.0
tensorboard==2.15.2
tensorboard-data-server==0.7.2
tensorflow==2.15.0.post1
tensorflow-estimator==2.15.0
tensorflow-hub==0.16.1
tensorflow-io-gcs-filesystem==0.36.0
tf-keras==2.15.0

With tensorflow 2.15.0.post1, tf-keras loads correctly under tensorflow-hub. I must have somehow misconfigured pip to pull pre-release versions on the other machine. Time for a rebuild...

from tf-keras.

sampathweb avatar sampathweb commented on June 2, 2024

When you use TensorFlow 2.16 with RC0 and testing Keras 2 path, please install pip install tf-keras~=2.16.0rc0 (will install RC2). If you use pip install tf-keras instead, it will install tf-keras==2.15 which is not compatible with TensorFlow 2.16.

The core of the issue is, in tf-keras 2.15 we didn't add a dependency to TensorFlow 2.15, so pip doesn't enforce that version compatibility. We fixed it in tf-keras 2.16, but may be we need to add a patch release for tf-keras 2.15 to avoid this.

@robertbcalhoun - Can you try this and confirm?

from tf-keras.

github-actions avatar github-actions commented on June 2, 2024

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

from tf-keras.

MaxiBoether avatar MaxiBoether commented on June 2, 2024

Just trying to avoid this issue becoming stale :-)

from tf-keras.

github-actions avatar github-actions commented on June 2, 2024

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

from tf-keras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.