AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'

14,661

Solution 1

The project "YOLOv3 model for object detection" has some issues with versions. I had the same issue and I used tensorflow 1.14.0 and keras 2.2.0.

Just overwrite the specific versions. Write in the command line.

pip install tensorflow==1.14.0
pip install keras==2.2.0

Solution 2

I installed tensorflow v1.14.0 using pip install tensorflow==1.14.0 and keras v2.2.0 using pip install keras==2.2.0 and it should definitely work.

Share:
14,661

Related videos on Youtube

Abu Noman Md Sakib
Author by

Abu Noman Md Sakib

As a self-confident and realistic person, looking for a challenging and responsible position which will enable me to utilize my knowledge, leadership skills, creativity, technical, analytical skills and to develop myself professionally with the experience gathered. Apart from all that I love to travel. I have summited the official highest peak of Bangladesh, witnessed the unofficial highest waterfall of Bangladesh, been to the mesmerizing Goecha La Trek in Yuksam, India. Have plans to do more.

Updated on June 04, 2022

Comments

  • Abu Noman Md Sakib
    Abu Noman Md Sakib almost 2 years

    I have been working on keras yolov3 model for object detection. This error keeps showing up. Here is the error:

    AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
    
    

    I don't know what to do. I have tried replacing "import keras.module.module" to "tensorflow.keras.module.module". But still it doesn't work.

    The full output code:

    runfile('G:/Traffic Violation Detection/object_detection.py', wdir='G:/Traffic Violation Detection')
    Using TensorFlow backend.
    Traceback (most recent call last):
    
      File "<ipython-input-3-0715decb6662>", line 1, in <module>
        runfile('G:/Traffic Violation Detection/object_detection.py', wdir='G:/Traffic Violation Detection')
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
        execfile(filename, namespace)
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)
    
      File "G:/Traffic Violation Detection/object_detection.py", line 6, in <module>
        from keras.layers.merge import add, concatenate
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\keras\__init__.py", line 3, in <module>
        from . import utils
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
        from . import conv_utils
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
        from .. import backend as K
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\keras\backend\__init__.py", line 1, in <module>
        from .load_backend import epsilon
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\keras\backend\load_backend.py", line 90, in <module>
        from .tensorflow_backend import *
    
      File "C:\Users\HP-NPC\Anaconda3\envs\virtual_platform\lib\site-packages\keras\backend\tensorflow_backend.py", line 54, in <module>
        get_graph = tf_keras_backend.get_graph
    
    AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
    

    My imports:

    import numpy as np
    from tensorflow.keras.layers import Conv2D, Input, BatchNormalization, LeakyReLU, ZeroPadding2D, UpSampling2D
    from keras.layers.merge import add, concatenate
    from tensorflow.keras.models import Model
    import struct
    import cv2
    import imageio
    
    

    For full code please visit: https://colab.research.google.com/drive/1oVR7swBqjfqxR50C3xt89w1vGEAaTFcK#scrollTo=rpSn_HsUHbGF

    • Abu Noman Md Sakib
      Abu Noman Md Sakib over 4 years
      I have added the link to my codes. @AccLok
  • Pramesh Bajracharya
    Pramesh Bajracharya almost 4 years
    I am loathing TensorFlow for this. Nothing works with a single version. Even with minor version change, big things break.
  • Abu Noman Md Sakib
    Abu Noman Md Sakib almost 4 years
    Totally agreed. Tensorflow is widely used. It should have been compatible in terms of version change. @PrameshBajracharya