This article mainly introduces Python, when using TensorFlow, execute import Keras error: AttributeError: module’tensorflow.compat.v2.__internal__’ has no attribute’tf2′ solution.
Sample code:
# Install required libs
# NOTE: Run this one code, then restart this runtime and run again for next all... (PENTING!!!)
### please update Albumentations to version>=0.3.0 for `Lambda` transform support
!pip install -U segmentation-models
!pip install q tensorflow==2.1
!pip install q keras==2.3.1
!pip install tensorflow-estimator==2.1.
## Imports libs
import os
os.environ [ 'CUDA_VISIBLE_DEVICES' ] = '0'
import cv2
import Keras
import NumPy as np
import matplotlib.pyplot as plt
Error message:
AttributeError Traceback (most recent call last)
<ipython-input-3-9c78a7be919d> in <module>()
5
6 import cv2
----> 7 import keras
8 import numpy as np
9 import matplotlib.pyplot as plt
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.compat.v2.__internal__' has no attribute 'tf2'
Solution:
!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.
## Imports libs
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"
from tensorflow import keras
import segmentation_models as sm
Similar Posts:
- docker:ImportError: libcuda.so.1: cannot open shared object file: No such file or directory
- [Solved] Tensorflow:ImportError: DLL load failed: The specified module cannot be found Failed to load the native TensorFlow runtime
- [Solved] ImportError: No module named tensorflow
- jupyter notebook error: No module named ‘tensorflow’
- Failed to load the native TensorFlow runtime [Solved]
- [Solved] ImportError: cannot import name pywrap_tensorflow
- Error reporting of importing tensorflow package from pycharm
- ImportError: cannot import name’e.g. utils’from’tensorflow.as.utils’ 38382;’ 39064;
- Tensorflow ImportError: DLL load failed with error code -1073741795
- ModuleNotFoundError: No module named ‘_pywrap_tensorflow_internal’ [How to Solve]