Skip to content Skip to sidebar Skip to footer

Tensorflow Backend Error. Attributeerror: Module 'tensorflow' Has No Attribute 'name_scope'

I'm using Version: 2.1.0 of TensorFlow and 2.3.1 of keras. While importing any module of keras i'm facing below tensorflow back-end error. import pandas as pd, numpy as np, os, re

Solution 1:

I recommend that you switch to using the keras module inside TensorFlow.

It is better maintained and you will not have incompatibility issues.

According to Francois Chollet:

Keras version 2.3.0 is here, and it is the last major multi-backend release. Going forward, users are recommended to switch their code over to tf.keras in TensorFlow 2.0. This release brings API changes and a few breaking changes. Have a look under the hood and see what it includes, as well as what the plans are going forward.

Switching all the imports instead of

from keras.modelsimportSequentialfrom keras.layersimportDense

to

from tensorflow.keras.modelsimportSequentialfrom tensorflow.keras.layersimportDense

will solve all your incompatibility issues.

You can uninstall Keras altogether as a separate package since it is already included by default in TensorFlow.

OBSERVATION: If PyCharm does not recognise tensorflow.keras, you will need to update PyCharm to the latest version >=2019.3. Only starting with that version is TensorFlow 2.0 recognised accordingly in PyCharm. Please consult the answer below for more information:

Unable to import Keras(from TensorFlow 2.0) in PyCharm

Post a Comment for "Tensorflow Backend Error. Attributeerror: Module 'tensorflow' Has No Attribute 'name_scope'"