keras: AttributeError: module 'keras.backend.tensorflow_backend' has no attribute '_is_tf_1'

System information

  • Ubuntu 18.04
  • TensorFlow backend
  • TensorFlow 1.14.0
  • Keras version: 2.2.4
  • Python version: 3.7.3

Describe the current behavior

import keras causes the following error to occur:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-88d96843a926> in <module>
----> 1 import keras

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/__init__.py in <module>
      1 from __future__ import absolute_import
      2 
----> 3 from . import utils
      4 from . import activations
      5 from . import applications

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/utils/__init__.py in <module>
     25 from .np_utils import to_categorical
     26 from .np_utils import normalize
---> 27 from .multi_gpu_utils import multi_gpu_model

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/utils/multi_gpu_utils.py in <module>
      5 from __future__ import print_function
      6 
----> 7 from ..layers.merge import concatenate
      8 from .. import backend as K
      9 from ..layers.core import Lambda

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/layers/__init__.py in <module>
      3 from ..utils.generic_utils import deserialize_keras_object
      4 from ..engine.base_layer import Layer
----> 5 from ..engine import Input
      6 from ..engine import InputLayer
      7 from ..engine.base_layer import InputSpec

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/engine/__init__.py in <module>
      6 from .base_layer import Layer
      7 from .network import get_source_inputs
----> 8 from .training import Model

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/engine/training.py in <module>
     19 from .training_utils import standardize_weights
     20 from .training_utils import weighted_masked_objective
---> 21 from . import training_arrays
     22 from . import training_generator
     23 from .. import backend as K

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/engine/training_arrays.py in <module>
     12 from .training_utils import check_num_samples
     13 from .. import backend as K
---> 14 from .. import callbacks as cbks
     15 from ..utils.generic_utils import Progbar
     16 from ..utils.generic_utils import slice_arrays

~/miniconda3/envs/wip/lib/python3.7/site-packages/keras/callbacks/__init__.py in <module>
     17 from .. import backend as K
     18 
---> 19 if K.backend() == 'tensorflow' and not K.tensorflow_backend._is_tf_1():
     20     from .tensorboard_v2 import TensorBoard
     21 else:

AttributeError: module 'keras.backend.tensorflow_backend' has no attribute '_is_tf_1'

Describe the expected behavior

No error when importing keras.

Code to reproduce the issue

import keras

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 22 (2 by maintainers)

Most upvoted comments

It sounds like an installation issue. Please try to uninstall and reinstall Keras:

pip uninstall keras
pip install keras --upgrade

It does not sort out my issue

It sounds like an installation issue. Please try to uninstall and reinstall Keras:

pip uninstall keras
pip install keras --upgrade

It works for me! I have been trying others methods

STEP 1: CREATING NEW ENVIRONMENT #open anaconda command prompt *type these commands:
a. conda create -n EnvironmentName python=3.5 anaconda Example (base) C:\Users\Asus>conda create -n py35 python=3.5 anaconda b. Activate EnvironmentName : type command: activate py35 Example (base) C:\Users\Asus>activate py35

STEP 2: INSTALL SPYDER ON NEW ENVIRONMENT #open anaconda command prompt *type this command: conda install spyder Example (py35) C:\Users\Asus>activate py35

STEP 3: INSTALL THEANO TO NEW ENVIRONMENT OF ANACONDA NEGIVATOR #open anaconda command prompt *type this command: conda install theano Example (py35) C:\Users\Asus>conda install theano

STEP 4:INSTALL TENSORFLOW TO NEW ENVIRONMENT OF ANACONDA NEGIVATOR #open anaconda command prompt *type this command: conda install tensorflow Example (py35) C:\Users\Asus>conda install tensorflow

STEP 5: GET TENSORFLOW FOR *GPU NOT for *CPU (not a complete step) #open anaconda command prompt *install latest pip if not latest *type this command: python -m pip install --upgrade pip

STEP 6: INSTALL KERAS *type command : conda install -c conda-forge keras Example (py35) C:\Users\Asus>conda install -c conda-forge keras

NOW IT SHOULD WORK Gives warning due to incomplete 5th step GIVES SOME WARNING BUT WORKS GOOD>>>>>>>>>

Same Issue.

Tensorflow : Version: 2.3.1 Keras : 2.4.3

Same issue AttributeError: module ‘keras.backend’ has no attribute ‘tensorflow_backend’

tensorflow 2.3.1 keras, 2.4.3

Same issue AttributeError: module ‘keras.backend’ has no attribute ‘tensorflow_backend’

tensorflow 2.3.1 keras, 2.4.3

It sounds like an installation issue. Please try to uninstall and reinstall Keras:

pip uninstall keras
pip install keras --upgrade

Thanks a lot. That’s truly helped!

I also occured the same thing , you can try this:

from tensorflow.keras import backend from keras import backend as K

IT WORKED FOR ME🎉

This issue seems to appear when installing keras (pip install keras) on the Spyder console. When installed on conda prompt, it worked for me.

It sounds like an installation issue. Please try to uninstall and reinstall Keras:

pip uninstall keras
pip install keras --upgrade

It works for me! I have been trying others methods

Worked for me too. Thanks

It works for me, thank you so much!