Skip to content
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

Error importing from Keras models - AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'tf2' #49172

Closed
ad12 opened this issue May 13, 2021 · 3 comments
Assignees
Labels

Comments

@ad12
Copy link

ad12 commented May 13, 2021

Please make sure that this is a bug. As per our
GitHub Policy,
we only address code/doc bugs, performance issues, feature requests and
build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 20.04
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • Keras version: 2.4.3
  • TensorFlow installed from (source or binary): source
  • TensorFlow version (use command below): 2.5.0
  • Python version: 3.7.10
  • Bazel version (if compiling from source): N/A
  • GCC/Compiler version (if compiling from source): N/A
  • CUDA/cuDNN version: N/A
  • GPU model and memory: N/A

Describe the current behavior
The following error is raised when importing Model from keras.models

dosma/models/oaiunet2d.py:14: in <module>
    from keras.models import Model
/opt/hostedtoolcache/Python/3.7.10/x64/lib/python3.7/site-packages/keras/__init__.py:20: in <module>
    from . import initializers
/opt/hostedtoolcache/Python/3.7.10/x64/lib/python3.7/site-packages/keras/initializers/__init__.py:124: in <module>
    populate_deserializable_objects()
/opt/hostedtoolcache/Python/3.7.10/x64/lib/python3.7/site-packages/keras/initializers/__init__.py:49: in populate_deserializable_objects
    LOCAL.GENERATED_WITH_V2 = tf.__internal__.tf2.enabled()
E   AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'tf2'

Describe the expected behavior
No error should be thrown

Contributing - Do you
want to contribute a PR? (yes/no): if this requires a fix, yes

Standalone code to reproduce the issue

from keras.models import Model

Other info / logs Include any logs or source code that would be helpful to
diagnose the problem. If including tracebacks, please include the full
traceback. Large logs and files should be attached.

@bhack
Copy link
Contributor

bhack commented May 13, 2021

Please import keras from Tensorflow:

import tensorflow as tf

And use tf.keras

@ad12
Copy link
Author

ad12 commented May 14, 2021

Great, thanks! I noticed the separate tf/keras imports worked up until tensorflow=2.4.1 - it seems as though the recent tensorflow 2.5.0 release caused this issue. Would it be useful to add this to the list of incompatibilities between the keras and tensorflow packages ?

@ad12 ad12 closed this as completed May 14, 2021
@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants