Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
845 views
in Technique[技术] by (71.8m points)

python 3.x - module 'tensorflow_core.compat.v2' has no attribute '__internal__'

I am using python 3.6.9 , keras 2.3.1, and (tf 2.0.0 or tf 2.1.0). Got the compatibility versions from this table.

When I import keras I get this error.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was able to replicate your issue with the below combination as shown below

!pip install tensorflow==2.1.0
!pip install keras==2.3.1
import keras

Output:

Using TensorFlow backend.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-88d96843a926> in <module>()
----> 1 import keras

8 frames
/usr/local/lib/python3.7/dist-packages/keras/initializers/__init__.py in populate_deserializable_objects()
     47 
     48   LOCAL.ALL_OBJECTS = {}
---> 49   LOCAL.GENERATED_WITH_V2 = tf.__internal__.tf2.enabled()
     50 
     51   # Compatibility aliases (need to exist in both V1 and V2).

AttributeError: module 'tensorflow_core.compat.v2' has no attribute '__internal__'

Fixed code:

Here issue is due to incompatibility between TF2.1 and Keras 2.3.1. Your issue can be resolved in two ways

  1. Upgrade to Keras2.5.0rc0 and import keras
  2. import keras from tensorflow as from tensorflow import keras

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...