python - 属性错误: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'

标签 python tensorflow keras keras-layer tf.keras

我一直在研究用于对象检测的 keras yolov3 模型。此错误不断出现。 这是错误:

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

我不知道该怎么办。我尝试将“import keras.module.module”替换为“tensorflow.keras.module.module”。但还是不行。

完整输出代码:

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'

我的导入:

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

完整代码请访问:https://colab.research.google.com/drive/1oVR7swBqjfqxR50C3xt89w1vGEAaTFcK#scrollTo=rpSn_HsUHbGF

最佳答案

项目“用于对象检测的YOLOv3模型”存在一些版本问题。我遇到了同样的问题,我使用了tensorflow 1.14.0和keras 2.2.0。

只需覆盖特定版本即可。在命令行中写入。

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

关于python - 属性错误: module 'tensorflow.python.keras.backend' has no attribute 'get_graph' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58963553/

相关文章:

python - Keras CNN 维度问题

python - 使用函数式 API 进行迁移学习和量化感知训练

python - 使用Python解码JSON,导出jqGrid时出错

python - 错误 : (wheel). whl 不是此平台上支持的轮子

python - ValueError : A `Concatenate` layer requires inputs with matching shapes except for the concat axis. 得到输入形状 : [(None, 523、523、32) 等

tensorflow - 在一对一样本上训练 Keras 模型并绘制验证曲线

python - 使用 PyTorch 和 TorchVision 对自定义数据集进行训练-验证-测试拆分

javascript - Bootstrap 单选按钮在 flask 中不起作用

python - 使用 SocketServer.TCPServer 通过 SSL 的 TCP 服务器

python - Keras - 获得训练层的重量