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

Created on 20 Sep 2019  Â·  19Comments  Â·  Source: keras-team/keras

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

tensorflow

Most helpful comment

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

pip uninstall keras
pip install keras --upgrade

All 19 comments

Experiencing a similar issue, while importing keras

STEP 1: CREATING NEW ENVIRONMENT

open anaconda command prompt

*type these commands:
a. conda create -n EnvironmentName python=3.5 anaconda
Example (base) C:UsersAsus>conda create -n py35 python=3.5 anaconda
b. Activate EnvironmentName : type command: activate py35
Example (base) C:UsersAsus>activate py35

STEP 2: INSTALL SPYDER ON NEW ENVIRONMENT

open anaconda command prompt

*type this command: conda install spyder
Example (py35) C:UsersAsus>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:UsersAsus>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:UsersAsus>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:UsersAsus>conda install -c conda-forge keras

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

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

pip uninstall keras
pip install keras --upgrade

I was trying to help others !! No errors on my side

On Mon, Sep 23, 2019, 01:57 François Chollet notifications@github.com
wrote:

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

pip uninstall keras
pip install keras --upgrade

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/keras-team/keras/issues/13352?email_source=notifications&email_token=AJT7LRICRNVI536YFV2I26LQK7IK3A5CNFSM4IY2VUYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7JOQII#issuecomment-533915681,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJT7LRJZK6AHWDGOCYFIPFLQK7IK3ANCNFSM4IY2VUYA
.

@fchollet following that, now the error is:

Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mac/miniconda3/envs/wip/lib/python3.7/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/home/mac/miniconda3/envs/wip/lib/python3.7/site-packages/keras/utils/__init__.py", line 26, in <module>
    from .vis_utils import model_to_dot
  File "/home/mac/miniconda3/envs/wip/lib/python3.7/site-packages/keras/utils/vis_utils.py", line 7, in <module>
    from ..models import Model
  File "/home/mac/miniconda3/envs/wip/lib/python3.7/site-packages/keras/models.py", line 10, in <module>
    from .engine.input_layer import Input
  File "/home/mac/miniconda3/envs/wip/lib/python3.7/site-packages/keras/engine/__init__.py", line 7, in <module>
    from .network import get_source_inputs
  File "/home/mac/miniconda3/envs/wip/lib/python3.7/site-packages/keras/engine/network.py", line 9, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

Then pip install pyyaml does nothing installs the package but does not resolve the issue.

Note that I'm not adversely affected by this (as I have previously setup environments I can use) but something might have gone wrong recently as this is now manifesting.

The fact that pip install pyyaml does not fix your import error likely indicates that the Python location used by your pip command and the Python location used by your python command (used to run the script) aren't the same. This is a common environment setup issue.

You can try to run which pip and which python to debug this.

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

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

pip uninstall keras
pip install keras --upgrade

it worked for my thank you so much!
i run these two commands in conda prompt because i am using python with anaconda. and it worked perfectly fine for me!

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!

It works for me, thank you so much!

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

This could possibly be due to multiple versions of Keras been installed.
Uninstalling Keras and reinstalling it will solve the issue.

It does not sort out my issue

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

This issue happened to me when I had installed Keras through the Anaconda environment list and then from conda prompt as well. Once I uninstalled Keras from both the places and installed it again from Conda prompt it worked for me.

AttributeError Traceback (most recent call last)
in ()
16
17 # K.set_image_dim_ordering('th')
---> 18 K.set_image_dim_ordering('tf')
19 K.set_image_data_format('channels_first')
20

AttributeError: module 'keras.backend' has no attribute 'set_image_dim_ordering'

Still experiencing the problem while using tensorflow=1.14.0 and keras=2.2.4.

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

tensorflow 2.3.1
keras, 2.4.3

Same Issue.

Tensorflow : Version: 2.3.1
Keras : 2.4.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harishkrishnav picture harishkrishnav  Â·  3Comments

MarkVdBergh picture MarkVdBergh  Â·  3Comments

zygmuntz picture zygmuntz  Â·  3Comments

Imorton-zd picture Imorton-zd  Â·  3Comments

vinayakumarr picture vinayakumarr  Â·  3Comments