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
- Upgrade to
Keras2.5.0rc0
and import keras
- import keras from tensorflow as
from tensorflow import keras
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…