close

[Solved] module ‘tensorflow.compat.v2.__internal__’ has no attribute ‘tf2’

Hello Guys, How are you all? Hope You all Are Fine. Today when I run my project I found module ‘tensorflow.compat.v2.internal’ has no attribute ‘tf2’ in Python. So Here I am Explain to you all the possible solutions here.

Without Wasting your time, Lets start This Article to Solve This Error.

How module ‘tensorflow.compat.v2__.internal__’ has no attribute ‘tf2’ Error Occurs ?

Today I am trying to use TensorFlow as backend yesterday I can use it, but today when I use it to show some error message when I’m trying to import Keras. it shows this error:

<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'

How To Solve module ‘tensorflow.compat.v2.__internal__’ has no attribute ‘tf2’ Error ?

  1. How To Solve module ‘tensorflow.compat.v2.__internal__’ has no attribute ‘tf2’ Error ?

    The reason for not showing TensorFlow backend is because in old keras it has three backed, and one of them was tf (AFAIK) but after tf 2.x, there is only one backed, which is tf, so that message is now depreciated

  2. module ‘tensorflow.compat.v2.__internal__’ has no attribute ‘tf2’

    The reason for not showing TensorFlow backend is because in old keras it has three backed, and one of them was tf (AFAIK) but after tf 2.x, there is only one backed, which is tf, so that message is now depreciated

Solution 1

Use this solution instead of what are you trying.

!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

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

Leave a Comment