keras ImportError:无法导入名称“transpose_shape”

kfgdxczn  于 2023-04-30  发布在  其他
关注(0)|答案(5)|浏览(249)

我正在学习Coursera,Andrew Ng的深度学习课程,使用YOLO算法进行对象检测,我试图使用Windows和Anaconda Navigator在PC上运行该算法,我安装了Keras在TensorFlow后端上运行。但当我输入以下内容时:

import tensorflow as tf
from keras import backend as K

它向我展示了以下内容:

Using TensorFlow backend.
Traceback (most recent call last):

  File "<ipython-input-8-0bcaeab92875>", line 2, in <module>
    from keras import backend as K

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
    from .tensorflow_backend import *

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 24, in <module>
    from ..utils.generic_utils import transpose_shape

ImportError: cannot import name 'transpose_shape'

似乎tensorflow_backend中的这一行有问题。py文件:

from ..utils.generic_utils import transpose_shape

帮助将不胜感激!干杯

qojgxg4l

qojgxg4l1#

尝试卸载tensorflow和keras并使用pip安装keras,它也安装tensorflow。对我很有效!!!

hi3rlvi2

hi3rlvi22#

可能是安装的软件包配置错误:

pip uninstall -y tensorflow keras tf-nightly keras-nightly

然后:

pip install tensorflow
o75abkj4

o75abkj43#

已尝试重新安装现有版本,但未成功。
我在运行Windows 10,Python 3。7.5 64位版本
对我有用的-安装Keras 2。3.1,Tensorflow 2。0

rta7y2nd

rta7y2nd4#

使用tensorflow。keras import backend as K而不是from keras import backend as K。

jdgnovmf

jdgnovmf5#

from tensorflow.keras import

因为Keras已经被TensorFlow拥有了。

相关问题